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 build_grid(key: str, n: int=128) -> Sequence[Sequence[int]]: num_ones = 0 grid = [] for i in range(n): hash_hex = Day10.knot_hash(f"{key}-{i}") hash_bin = bin(int(hash_hex, 16))[2:].zfill(n) row = list(map(int,hash_bin)) num_ones += sum(row) grid.append(row) return num_ones, grid
def test_part2(self): inputs = ["", "AoC 2017", "1,2,3", "1,2,4"] outputs = [ "a2582a3a0e66e6e86e3812dcb672a272", "33efeb34ea91902bb2f59c9920caa6cd", "3efbe78a8d82f29979031a4aa0b16a9d", "63960835bcdc130f0b66d7ff4f6a5a8e" ] for input, output in zip(inputs, outputs): actual = Day10.solve_part2(input) self.assertEqual( actual, output, f"input={input}, expected={output}, actual={actual}")
def test_part1(self): self.assertEqual(Day10.solve_part1(self.input, {3, 5}), 0)
def setUp(self) -> None: self.input = Day10().read_file("tests/test_day10.txt")
def test_part2(self): self.assertEqual(Day10.solve_part2(self.input), 30)
def test_part1(self): self.assertEqual(Day10.solve(1, 5), 6)
def test_part1(self): input = "3,4,1,5" output = 12 actual = Day10.solve_part1(input, num_elements=5) self.assertEqual(actual, output, f"input={input}, expected={output}, actual={actual}")
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))