Day 25 - Advent of Code 2024
25 December 2024
Working solutions for the day 25 puzzles.
Part One
""" day_25_01.py """
# usage: python3 day_25_01.py < input
import itertools
import sys
def profile(patterns):
""" calculate heights for each pattern """
def heights(pattern):
""" calculate heights for pattern """
output = len(pattern[0]) * [-1]
for p in pattern:
for i, c in enumerate(p):
output[i] += 1 if c == '#' else 0
return output
return [heights(p) for p in patterns]
def fit(xs, ys):
""" do xs and ys fit """
for x, y in zip(xs, ys):
if x + y > 5:
return False
return True
keylocks = []
with sys.stdin as infile:
keylock = []
for line in infile:
row = line.strip()
if row != '':
keylock.append(row)
else:
keylocks.append(keylock)
keylock = []
keylocks.append(keylock)
keys = [p for p in keylocks if p[-1] == '#####']
locks = [p for p in keylocks if p[0] == '#####']
answer = 0
for key, lock in itertools.product(profile(keys), profile(locks)):
answer += 1 if fit(key, lock) else 0
print(answer)
Part Two