You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
AdventOfCode19/days/test_day4.py

35 lines
869 B

from collections import Counter
def check_num(num):
numarr = [int(d) for d in (str(num))]
for p in range(1, 6):
if numarr[p-1] > numarr[p]:
return False
c = Counter(str(num))
return len({k: v for k, v in c.items() if v >= 2}) > 0
def check_num_grp(num):
numarr = [int(d) for d in (str(num))]
for p in range(1, 6):
if numarr[p-1] > numarr[p]:
return False
c = Counter(str(num))
return len({k: v for k, v in c.items() if v == 2}) > 0
def test_day4a():
counter = 0
for num in range(168630, 718099):
if check_num(num) is True:
counter += 1
assert counter == 1686
def test_day4b():
counter = 0
for num in range(168630, 718099):
if check_num_grp(num) is True:
counter += 1
assert counter == 1145