diff --git a/2024-python/output/day_12.py b/2024-python/output/day_12.py new file mode 100644 index 0000000..712e3e1 --- /dev/null +++ b/2024-python/output/day_12.py @@ -0,0 +1,86 @@ +import re +from collections import Counter, defaultdict, deque +from heapq import heappop, heappush +from itertools import chain, combinations, compress, permutations + +from output import ADJ, DD, D, ccw, cw, ints, matrix, mdbg, mhd, vdbg + + +def solve(data): + grid, H, W = matrix(data) + p1 = 0 + seen = set() + for r, row in enumerate(grid): + for c, col in enumerate(row): + if (r, c) in seen: + continue + areas = 0 + perimeters = 0 + q = deque([(r, c)]) + while q: + rc = q.popleft() + if rc in seen: + continue + seen.add(rc) + areas += 1 + y, x = rc + for dy, dx in D: + if (0 <= y + dy < H and 0 <= x + dx