aoc2020/2.py
2020-12-14 04:45:56 -06:00

20 lines
493 B
Python

count1 = 0
count2 = 0
with open("2.txt") as f:
for line in f:
spec, data = line.split(": ")
nums, letter = spec.split(" ")
lo, hi = nums.split("-")
lo = int(lo)
hi = int(hi)
c = data.count(letter)
if c >= lo and c <= hi:
count1 += 1
a = lo - 1 < len(data) and data[lo - 1] == letter
b = hi - 1 < len(data) and data[hi - 1] == letter
if a ^ b:
count2 += 1
print(count1)
print(count2)