def main(): day_n = sys.argv[1] if day_n[:-1] == 'day1': day = Day01(read_file) elif day_n[:-1] == 'day2': day = Day02(read_file) elif day_n[:-1] == 'day3': day = Day03(read_file) elif day_n[:-1] == 'day4': day = Day04() elif day_n[:-1] == 'day5': day = Day05(read_file) elif day_n[:-1] == 'day6': day = Day06(read_file) elif day_n[:-1] == 'day7': day = Day07(read_file) elif day_n[:-1] == 'day8': day = Day08(read_file) elif day_n[:-1] == 'day9': day = Day09(read_file) elif day_n[:-1] == 'day10': day = Day10(read_file) if day_n[-1:] == 'a': print(day.run_solution1()) elif day_n[-1:] == 'b': print(day.run_solution2())
def addrow(grid, s, i): input = range(0, 256) day10 = Day10(list(input)) h = day10.hash2(s + '-' + str(i)) grid.append(knothash2bin(h)) return grid
def part2(s): input = range(0, 256) day10 = Day10(list(input)) grid = reduce((lambda g, i: addrow(g, s, i)), range(0, 128), []) part2 = Part2(grid) return part2.countgroups()
def part1(s): input = range(0, 256) day10 = Day10(list(input)) usedcount = 0 for i in range(0, 128): h = day10.hash2(s + '-' + str(i)) usedcount += knothash2bin(h).count('1') return usedcount
def setUp(self) -> None: self.input = Day10().read_file("tests/test_day10.txt")
def test_part1(self): input = Day10().read_file("tests/test_day10.1.txt") self.assertEqual(Day10.solve_part1(input), 35) input = Day10().read_file("tests/test_day10.2.txt") self.assertEqual(Day10.solve_part1(input), 220)
def test_part2(self): input = Day10().read_file("tests/test_day10.3.txt") self.assertEqual(Day10.solve_part2(input), 8) input = Day10().read_file("tests/test_day10.4.txt") self.assertEqual(Day10.solve_part2(input), 19208)
def setUp(self): input = range(0, 256) self.day10 = Day10(list(input))