From 4a990c1f6cb8a8642594e16720a65ff613f0b3c2 Mon Sep 17 00:00:00 2001 From: flifloo Date: Wed, 4 Dec 2019 10:09:53 +0100 Subject: [PATCH] Day 4 P2 --- 2019/day 4/P2/input.txt | 1 + 2019/day 4/P2/password.py | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 2019/day 4/P2/input.txt create mode 100644 2019/day 4/P2/password.py diff --git a/2019/day 4/P2/input.txt b/2019/day 4/P2/input.txt new file mode 100644 index 0000000..a70b274 --- /dev/null +++ b/2019/day 4/P2/input.txt @@ -0,0 +1 @@ +246540-787419 diff --git a/2019/day 4/P2/password.py b/2019/day 4/P2/password.py new file mode 100644 index 0000000..5517362 --- /dev/null +++ b/2019/day 4/P2/password.py @@ -0,0 +1,23 @@ +pswrange = [int(i) for i in open("input.txt").read().split("-")] + +valid = 0 +for i in range(pswrange[0], pswrange[1]): + i = str(i) + l = list(i) + c = 0 + dec = False + double = False + while c < len(l)-1: + if l[c] <= l[c+1]: + pass + else: + dec = True + break + if f"{l[c]}{l[c]}" in i and not f"{l[c]}{l[c]}{l[c]}" in i: + double = True + c+=1 + if not dec and double: + valid+=1 + +print(valid) +