diff options
Diffstat (limited to '2020/aoc2020-d02.py')
| -rw-r--r-- | 2020/aoc2020-d02.py | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/2020/aoc2020-d02.py b/2020/aoc2020-d02.py new file mode 100644 index 0000000..9871373 --- /dev/null +++ b/2020/aoc2020-d02.py @@ -0,0 +1,22 @@ +#advent of code 2020 +#day 02 + +p1 = 0; +p2 = 0; +PuzzleInput = open("02.in","r"); +for l in PuzzleInput: + rules, pwd = l.split(": "); + limits, letter = rules.split(" "); + lo, hi = limits.split("-"); + check = pwd.count(letter); + if int(lo) <= check and int(hi) >= check: + p1 += 1; + v1 = pwd[int(lo)-1] == letter; + v2 = pwd[int(hi)-1] == letter; + v3 = v1 + v2; + v4 = v1 != v2; + if v3 and v4: p2 += 1; +PuzzleInput.close(); + +print("part 1 =",p1); +print("part 2 =",p2); |
