Day 7 - Advent of Code 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:
splitters[(r, c)] = True
continue
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) - 1
if __name__ == '__main__':
test(get('example01'), 21)
puzzle = get('input')
solution = solve(puzzle)
print(solution)
Part Two
