def test_day10_part2(): assert day10.part2( '''.#....#####...#.. ##...##.#####..## ##...#...#.#####. ..#.....X...###.. ..#.#.....#....##''', None, 35) == 1403 assert day10.part2( '''.#..##.###...####### ##.############..##. .#.######.########.# .###.#######.####.#. #####.##.#.##.###.## ..#####..#.######### #################### #.####....###.#.#.## ##.################# #####.##.###..####.. ..######..##.####### ####.##.####...##..# .#####..#.######.### ##...#.##########... #.##########.####### .####.#.###.###.#.## ....##.##.###..##### .#.#.###########.### #.#.#.#####.####.### ###.##.####.##.#..##''', (11, 13)) == 802
def test_part2(self): got = part2("1,2,3") want = "3efbe78a8d82f29979031a4aa0b16a9d" self.assertEqual(got, want) got = part2("1,2,4") want = "63960835bcdc130f0b66d7ff4f6a5a8e" self.assertEqual(got, want) got = part2("AoC 2017") want = "33efeb34ea91902bb2f59c9920caa6cd" self.assertEqual(got, want) got = part2("") want = "a2582a3a0e66e6e86e3812dcb672a272" self.assertEqual(got, want)
def test_second_ex_part2(self): f = 'day10-test2.txt' input_list: List[int] = common.read_list(f) input_list = day10.prep_list(input_list) answer: int = day10.part2(input_list) self.assertEqual(19208, answer)
def test_destoyer(): lines = ['.#....#####...#..','##...##.#####..##','##...#...#.#####.','..#.....#...###..','..#.#.....#....##'] (field,x,y) = day10.genField(lines) v = day10.genVectors(max(x,y)) (ba, num) = day10.part1(field,v) print(ba) la = day10.part2(field,v,ba,36) assert la == (14+3j)
def _grid(line): grid = [] for x in range(128): res = day10.part2(list(range(256)), '{line}-{x}'.format(line=line, x=x)) # This can be done better res = list(''.join(['{:04b}'.format(int(n, base=16)) for n in res])) res = [int(r) for r in res] grid.append(res) return grid
def part2(input): grid = [] for x in range(128): hash = day10.part2(input + '-' + str(x)) grid.append([c for c in hex2bin(hash)]) regions = 0 for x in range(128): for y in range(128): if grid[y][x] == '1': regions += 1 # how to grow a region? bfs, skipping if not '1' todo = [(x, y)] while todo: cx, cy = todo.pop() grid[cy][cx] = '#' # instead of visited for dx, dy in [(-1, 0), (1, 0), (0, -1), (0, 1)]: px = cx + dx py = cy + dy if px < 128 and px >= 0 and py < 128 and py >= 0: if grid[py][px] == '1': todo.append((px, py)) return regions
def test_part2(): assert part2() == 'dc7e7dee710d4c7201ce42713e6b8359'
def test_part2_main(self): grid = parse("../input.txt") magic_num = part2(grid) self.assertEqual(806, magic_num)
def test_part2_1(self): grid = parse("../input_small5.txt") magic_num = part2(grid) self.assertEqual(magic_num, 802)
def test_part2_on_example_b(self): input = read_inputfile("example10b.txt") self.assertEqual(day10.part2(input), 19208)
inp = "ugkiagan" keys = ['{}-{}'.format(inp, i) for i in range(128)] from day10 import part2, getasciilens hashed = [format(int(part2(getasciilens(k)), 16), '0128b') for k in keys] total1s = sum([sum([1 if s == '1' else 0 for s in h]) for h in hashed]) print('\n'.join(hashed)) print(total1s) # part2 - flood fill each region of 1s region = [[0 for i in range(128)] for j in range(128)] next_region = 1 def neighbours(r, c, sz): if r < sz - 1: yield (r + 1, c) if r > 0: yield (r - 1, c) if c > 0: yield (r, c - 1) if c < sz - 1: yield (r, c + 1) for row in range(128): for column in range(128): bit = hashed[row][column] == '1' if bit and region[row][column] == 0: # unassigned, start flooding
def test_part2_example1(self): result = day10.part2(self.example) self.assertEqual(result, 3)
def test_10_2_examples(): examples = [] for (inp, out) in examples: assert out == day10.part2(inp)
def test_part2_example_small(self): self.assertEqual(8, day10.part2("../inputs/day10_example_small.txt"))
def test_part2(self): self.assertEqual(113387824750592, day10.part2("../inputs/day10.txt"))
def test_day10_part2a(): assert day10.part2(day10_1) == 8
def test_part2_sample(sample_data): assert part2(sample_data) == 8
def part1(input): used = 0 for x in range(128): hash = day10.part2(input + '-' + str(x)) used += hex2bin(hash).count('1') return used
def generate_hex_grid(puzzle_input): return [day10.part2("%s-%d" % (puzzle_input, row)) for row in range(128)]
def test_part2_input(self): result = day10.part2(aoc.read_input('day10.input')) self.assertEqual(612, result)
def test_part2_example1(self): result = day10.part2(self.input_list_example5) self.assertEqual(802, result)
def test_day10_part2b(): assert day10.part2(day10_2) == 19208
def test_part2_input(input_data): assert part2(input_data) == 31581162962944
def sample(): sample = 'flqrgnkx' for x in range(8): hash = day10.part2(sample + '-' + str(x)) print(hex2bin(hash)[:8]) print('sample', part1(sample))
def test_day10_part_2(): number_list = [int(i) for i in test_input_data] assert day10.part2(number_list) == 19208 number_list2 = [int(i) for i in input_data] assert day10.part2(number_list2) == 13816758796288
def test_day10_part2(): data1 = int_array_from_list("10.txt", test=True) data2 = int_array_from_list("10b.txt", test=True) assert day10.part2(data1) == 8 assert day10.part2(data2) == 19208
def test_part2_example_large(self): self.assertEqual(19208, day10.part2("../inputs/day10_example_large.txt"))
def test_part2(puzzle_input, answer): assert part2(puzzle_input) == answer
def test_part2(): assert part2(test_input) == 288957
def test_part2_lrg_example(self): self.assertEqual(day10.part2(self.exampleInputLrg), 19208)