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/day4.py

35 lines
1.0 KiB

import unittest
import os
from collections import Counter
class Day4(unittest.TestCase):
def check_num(self, 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(self, 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(self):
counter = 0
for num in range(168630, 718099):
if self.check_num(num) is True:
counter += 1
self.assertEqual(counter, 1686)
def test_day4b(self):
counter = 0
for num in range(168630, 718099):
if self.check_num_grp(num) is True:
counter += 1
self.assertEqual(counter, 1145)