My Advent of Code solutions in Python. kevinyap.ca/2019/12/going-fast-in-advent-of-code/
advent-of-code python
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Add solution for 2024/08

+31
+31
2024/day08.py
··· 1 + import fileinput 2 + from itertools import permutations 3 + from collections import defaultdict 4 + 5 + from utils import Point 6 + 7 + 8 + # Parse problem input. 9 + BOARD = {} 10 + ANTENNAE = defaultdict(set) 11 + for y, line in enumerate(fileinput.input()): 12 + for x, c in enumerate(line.strip()): 13 + p = Point(x, y) 14 + BOARD[p] = c 15 + if c != '.': 16 + ANTENNAE[c].add(p) 17 + 18 + # Solve problem. 19 + part_1_antinodes = set() 20 + part_2_antinodes = set() 21 + 22 + for freq, locs in ANTENNAE.items(): 23 + for a, b in permutations(locs, 2): 24 + for i in range(len(line)): 25 + antinode = b + (b - a) * i 26 + part_2_antinodes.add(antinode) 27 + if i == 1: 28 + part_1_antinodes.add(antinode) 29 + 30 + print("Part 1:", len(part_1_antinodes & set(BOARD))) 31 + print("Part 2:", len(part_2_antinodes & set(BOARD)))