Day 7 - Advent of Code 2025
7 December 2025
Working solutions for the day 7 puzzles.
Part One
""" day_07_01.py """
# usage: python3 day_07_01.py
def get(filename):
""" contents of filename """
with open(filename, 'r', encoding='utf-8') as infile:
data = infile.read()
return data
def test(data, given_solution):
""" testing """
assert solve(data) == given_solution
def solve(data):
""" solve the puzzle """
splitters = {(r, c): False for r, row in enumerate(data.splitlines())
for c, col in enumerate(row) if col in ['S', '^']}
for (r, c), _ in splitters.items():
if r != 0:
for y in range(r - 1, -1, -1):
if (y, c) in splitters:
if y == 0:
splitters[(r, c)] = True
break
splitters[(r, c)] = (splitters.get((y, c - 1), False) or
splitters.get((y, c + 1), False))
if splitters[(r, c)]:
break
return list(splitters.values()).count(True)
if __name__ == '__main__':
test(get('example01'), 21)
puzzle = get('input')
solution = solve(puzzle)
print(solution)
Part Two
""" day_07_02.py """
# usage: python3 day_07_02.py
def get(filename):
""" contents of filename """
with open(filename, 'r', encoding='utf-8') as infile:
data = infile.read()
return data
def test(data, given_solution):
""" testing """
assert solve(data) == given_solution
def solve(data):
""" solve the puzzle """
splitters = {(r, c): 0 for r, row in enumerate(data.splitlines())
for c, col in enumerate(row) if col in ['S', '^']}
for (r, c), _ in splitters.items():
if r != 0:
for y in range(r - 1, -1, -1):
if (y, c) in splitters:
if y == 0:
splitters[(r, c)] = 1
break
splitters[(r, c)] += (splitters.get((y, c - 1), 0) +
splitters.get((y, c + 1), 0))
return sum(value for _, value in splitters.items()) + 1
if __name__ == '__main__':
test(get('example01'), 40)
puzzle = get('input')
solution = solve(puzzle)
print(solution)
