from tools.coordinate import Coordinate from tools.grid import Grid from day10 import knot_hash from tools.aoc import AOCDay from typing import Any class Day(AOCDay): inputs = [ [ (8108, "input14_test"), (8316, "input14") ], [ (1242, "input14_test"), (1074, "input14") ] ] def part1(self) -> Any: key_start = self.getInput().strip() + '-' count = 0 for x in range(128): hash = knot_hash(key_start + str(x)) bin_hash = bin(int(hash, 16))[2:].zfill(128) count += bin_hash.count('1') return count def part2(self) -> Any: key_start = self.getInput().strip() + '-' grid = Grid() for y in range(128): hash = knot_hash(key_start + str(y)) bin_hash = bin(int(hash, 16))[2:].zfill(128) for x, c in enumerate(bin_hash): grid.set(Coordinate(x, y), c == '1') count = 0 ignore_list = [] for c in grid.getActiveCells(): if c not in ignore_list: count += 1 ignore_list += grid.getActiveRegion(c) return count if __name__ == '__main__': day = Day(2017, 14) day.run(verbose=True)