aoc

Advent of Code
git clone https://git.pngu.org/aoc
Log | Files | Refs | README

commit ded8054651350247d5dcb3e4a0f786d1d0dc4edd
parent 7a7a8ed3bdce9891f244a2e9a2d615b2e44d5bba
Author: Jack Sangdahl <jack@pngu.org>
Date:   Sun,  7 Dec 2025 09:01:18 +0100

Day 7 2025

Diffstat:
A2025/7_2025.py | 43+++++++++++++++++++++++++++++++++++++++++++
Adata/7_2025.txt | 142+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 185 insertions(+), 0 deletions(-)

diff --git a/2025/7_2025.py b/2025/7_2025.py @@ -0,0 +1,43 @@ +from collections import deque +from functools import cache + +input = open("data/7_2025.txt").read() +grid = [list(i) for i in input.splitlines()] +r, c = len(grid), len(grid[0]) + +for i in range(r): + for j in range(c): + if grid[i][j] == "S": + sr, sc = i, j + + +@cache +def score(x, y): + if x + 1 == r: + return 1 + if grid[x + 1][y] == "^": + return score(x + 1, y - 1) + score(x + 1, y + 1) + else: + return score(x + 1, y) + + +p1, vis = 0, set() +q = deque([(sr, sc)]) +while q: + x, y = q.popleft() + if (x, y) in vis: + continue + vis.add((x, y)) + if x + 1 == r: + continue + if grid[x + 1][y] == "^": + q.append((x + 1, y - 1)) + q.append((x + 1, y + 1)) + p1 += 1 + else: + q.append((x + 1, y)) + +p2 = score(sr, sc) + +print(p1) +print(p2) diff --git a/data/7_2025.txt b/data/7_2025.txt @@ -0,0 +1,142 @@ +......................................................................S...................................................................... +............................................................................................................................................. +......................................................................^...................................................................... +............................................................................................................................................. +.....................................................................^.^..................................................................... +............................................................................................................................................. +....................................................................^...^.................................................................... +............................................................................................................................................. +...................................................................^...^.^................................................................... +............................................................................................................................................. +..................................................................^.^.^.^.^.................................................................. +............................................................................................................................................. +.................................................................^.^.^.^.^.^................................................................. +............................................................................................................................................. +................................................................^.^.......^.^................................................................ +............................................................................................................................................. +...............................................................^.....^.....^.^............................................................... +............................................................................................................................................. +..............................................................^.^.........^...^.............................................................. +............................................................................................................................................. +.............................................................^.^...^.....^.^.^.^............................................................. +............................................................................................................................................. +............................................................^.^.^.....^.^.^...^.^............................................................ +............................................................................................................................................. +...........................................................^.^.....^...^...^.^.^.^........................................................... +............................................................................................................................................. +..........................................................^.^.^.^.^.^...^.......^.^.......................................................... +............................................................................................................................................. +.........................................................^.^.^...^.^...^.^.^.....^.^......................................................... +............................................................................................................................................. +........................................................^.^.^...^.^.^.....^.^.^.^...^........................................................ +............................................................................................................................................. +.......................................................^...^.^...^.^.^.^.^.^.^...^.^.^....................................................... +............................................................................................................................................. +......................................................^.^.....^.....^.^...^.^.^.^.....^...................................................... +............................................................................................................................................. +.....................................................^.....^.^.^.^...^.^.^.^.^.^.^.^.^.^..................................................... +............................................................................................................................................. +....................................................^...^.^.^.^...^...^.^.^.^...^.^.....^.................................................... +............................................................................................................................................. +...................................................^.^...^.^.^...^.^.....^.^.^.^.^...^.^.^................................................... +............................................................................................................................................. +..................................................^.......^...^.^.^.^.^.^.^.^.^.^.^.^.....^.................................................. +............................................................................................................................................. +.................................................^...^...^...^.^.^.........^...^.^.....^.^.^................................................. +............................................................................................................................................. +................................................^...^.^.....^.^.^...^.^.^.^.^.^.......^...^.^................................................ +............................................................................................................................................. +...............................................^.^...^...^.........^.^.^.^.^.^.....^.^.....^.^............................................... +............................................................................................................................................. +..............................................^.^...^...^.^.^.^.^.^.^.^...^.^.^.^...^.^.^.....^.............................................. +............................................................................................................................................. +.............................................^.^.^...^...^.^.^.^...^.^.^.^.^.^.^...^.^.^.^.^...^............................................. +............................................................................................................................................. +............................................^...^.^.^.^.....^.^...^.^.^.^.^.....^.^.^...^.^.^...^............................................ +............................................................................................................................................. +...........................................^.^.^.......^.^.^...^...^...^...^.....^...^.^.^.^.....^........................................... +............................................................................................................................................. +..........................................^...^.^.^.^.^...^.^.^.^.^.^...^.^...^.^.^...^.^.^...^.^.^.......................................... +............................................................................................................................................. +.........................................^...^.^...^.^.......^...^.^...^.^...^.^.^.^.^.^.^.^.^...^.^......................................... +............................................................................................................................................. +........................................^.^...^.^.........^.^.^.^.^.^.....^.^.^.....^.^.^.^.^...^...^........................................ +............................................................................................................................................. +.......................................^.^.^.^...^.....^.^.^.^.^...^.^...^.^.^.^.^.^...^.^.^...^...^.^....................................... +............................................................................................................................................. +......................................^.^.^.^.^.^.^.....^.^.^.^.^.^.^.^...^.....^.^.^...^.^.^.^.^.^.^.^...................................... +............................................................................................................................................. +.....................................^.^.^.^.^.^.^.^...^.^...^.^.^.^...^.....^.^.^...^.^...^.^.^...^...^..................................... +............................................................................................................................................. +....................................^.^.......^.^.^...^.^.^.^.^...^.^.^...^.^...^...^...^.....^.^.....^.^.................................... +............................................................................................................................................. +...................................^.^.^.^.^.^.....^.^.^.^.^.^.^...^.^...^...^.^.^...^.^.^.^...^.^...^...^................................... +............................................................................................................................................. +..................................^.....^.^.^.^...^.^.^.^.^.^...^.^.......^...^.^.^.^.^...^.^.^...^...^...^.................................. +............................................................................................................................................. +.................................^.^.^.^.^.^.^...^.^.^.^.^.^.^.^.^.^.^.^...^...^.....^.^.^.^.^.^...^.^.....^................................. +............................................................................................................................................. +................................^.^...^.^.^.^.^.^...^.^.^...^...^.^.^.^.^...^...^.....^.^.^.^.^.....^.....^.^................................ +............................................................................................................................................. +...............................^.....^.^.^.^.^.^...^.^.^.^...^.^...^.....^...^.....^...^...^.^...^.^.^...^.^.^............................... +............................................................................................................................................. +..............................^.^.....^.^.^.^.^.^.^.^...^.^.^.^.^.^...^.^.....^.^.^...........^.^...^...^...^.^.............................. +............................................................................................................................................. +.............................^...^.....^.^.^.^...^.....^.^.^.^.........^.^.^...^.^.^...^.^.^.^.^.^.^.^.^...^...^............................. +............................................................................................................................................. +............................^.^.^...^.^.^.^...^.....^.^.^.^.^...^.^.^.^.^...^...^.^.^.^.^...^.^.^.^...^.^.^.^...^............................ +............................................................................................................................................. +...........................^.^.......^.....^.^.....^...^.^.^...^.^.^.^.^.^...^.^.^.^.^.^...^.^.^.^.......^.^.^...^........................... +............................................................................................................................................. +..........................^.^.^.^.....^.^.^.......^...^.^...^...^.^.^.^.....^...^.^.^.^...^.^...^...^.^.^...^.^...^.......................... +............................................................................................................................................. +.........................^...^...^.^.^.^...^...^.^.^.^...^.^.^.^.^...^.^.........^.^.^.^.^...^.^.^...^.....^.......^......................... +............................................................................................................................................. +........................^.^...^.^.^.^.^.^.^...^.^.^...^.^.^...^.^.^.^.^.^.^.^.^.^.^...^.^...^.^.^.^.^.....^.^.^.....^........................ +............................................................................................................................................. +.......................^.^.^.......^.^...^.^.^.^.^.^...^.......^.^.^.^.^...^...^.^...^.^.^.^.^.^.^.^...^.^...^.^.^...^....................... +............................................................................................................................................. +......................^.^.^...^.^.^...^.^.^.^.^...^...^...^.^.^.^.^.^.^.^.^.^.^.^...^.....^.^...^.^.^.^.^.^.^.^.......^...................... +............................................................................................................................................. +.....................^.^.^.^...^...^.^...^.^.^.^.^.^...^.^.^.....^.^...^.....^.^.^.^.....^.^.^.^.^.^.^.^.^.^.^.^.^.^...^..................... +............................................................................................................................................. +....................^.^.^.^.^.^.^.^.^.^.........^.^.^...^.^.^.^.......^.^.^.^.^.....^.^.^.^.^.^.^.^.^.^.^...^...^.....^.^.................... +............................................................................................................................................. +...................^.^.^.^.^.^.^.....^.^.^.^.^.^.....^.^.....^.^.....^.^.........^...^...^.^...^.^...^.^.^.^.^.^.^.^.....^................... +............................................................................................................................................. +..................^.....^...^.^.^.^...^.^.^.^.^.^...^.^.^.^.^.^.^.^.^.^.....^.......^...^...^.......^.^.^.^.^.^...^.^.....^.................. +............................................................................................................................................. +.................^.^.^.^...^.^.^.^.........^.^.^.....^.^.^.^.......^...^.^...^...^.^.^.....^.^...^...^.^.^.....^.^...^.^.^.^................. +............................................................................................................................................. +................^...^.^...^.^...^.^.^.^.^...^.^.........^...^.^.....^...^.^...^.^...^.^...^.^.^.^.^.^...^.^.^...^.^.^.^.^...^................ +............................................................................................................................................. +...............^.^.^.......^.^.^...^.^.^.^.^...^...^.^...^...^.^.^.^...^.^.^.^.^.^.^.^...^.^...^.....^...^.^...^.^.....^.^...^............... +............................................................................................................................................. +..............^...^.....^.^.^.^.^.^...^...^.....^.^.^.^.^.^...^.^.^.^...^.^.^...^...^.^.^.......^...^.^...^.^.^.^.......^.^...^.............. +............................................................................................................................................. +.............^...^...^.^...^.^.^.^.^.^...^...^.^.^.^.^.^.....^...^...^.....^...^.^.....^.^.^.^.^.^.^.^.^.^.^.....^.^.^.^.^.^...^............. +............................................................................................................................................. +............^...^.^.^...^.^...^.^.^.^.^.......^.^.....^.....^.^.^.^.^...^.^.^.^...^.....^.^...^.^.^.^.^.^.^.^.^.^.^.^.^.....^.^.^............ +............................................................................................................................................. +...........^.^.^.....^.^.^.^.^.^.^.^...^.^.^...^.^.^.^.....^...^.^.^...^.^...^.^.^...^.^.^.^...^.^.^...^...^.^.^.^...^.....^.^.^.^........... +............................................................................................................................................. +..........^.^.^.^...^.^...^...^...........^.^.^.^.^.^.^.^...^.^.^.^.^.^...........^.^.^...^.^.^.^.....^.^.^.^.^.^.^.^.^...^.^.^.^.^.......... +............................................................................................................................................. +.........^.^.^.^...^.^...^...^...^.......^...^.^.....^.^.^.....^.^.^.^...^.^...^.^.^.^.....^.^.^.^.^...^.^...^.^...^.^...^.^...^.^.^......... +............................................................................................................................................. +........^.^.....^.^.^.^...^.^.^.^.....^.^...^.^.^.^.....^.^.^.^.^.^.^.^...^.^.....^.^.....^.^.^.^.^.^.^.^.^.^.^.^.^...^...^.^.^.^...^........ +............................................................................................................................................. +.......^.^.^.^.^.....^.....^.^.^.^.^...^...^...^...^.^.^.^.^.......^...^.^...^.^.^.^.^.^.^...^.^.^...^.^.^.^...^.^.^.^.^...^.^.^...^.^....... +............................................................................................................................................. +......^.^.^.^.^...^.^.^...^.^.^.^.^.^.^.^...^.^...^.^.^...^.^.^.^.^.^...^.^.....^...^.^.^...^.^...^.....^.^.^.^.^.^.^.^.^.^.^.....^.^.^...... +............................................................................................................................................. +.....^.^.^.^.^.^.^.^...^.^.^.......^.^.^.^...^.^.^.....^.^.....^.^...^.^.^...^.^.^.^.^.^.^.^.^.^...^.^.^...^.^.^.^.^.....^.^.^.^.^.^...^..... +............................................................................................................................................. +....^...^.^.^.^.^.^.^...^.^.^...^.^.^.^...^.^.^.....^.^...^.^.^.^...^.^.^.....^.^.^.^.^.....^.^.^.^...^.^.^.^.^.^.^.^...^.^.^.^.^.^.^.^.^.... +............................................................................................................................................. +...^...^.......^.^...^.^.^.^...^.^.^.^.....^...^.^.......^.^.^.^.^.^.^.^...^.^.....^.^.^.^.^.^.^.^.....^.^...^...^.^.^.....^...^.......^.^... +............................................................................................................................................. +..^.^.^...^.^.^.....^.^.^...^...^...^...^.^.^.^.^.^.^.....^.^.^...^.....^.^.^.^.^...^.^...^.^.^.^.^.^.^.^...^.^.^...^.^.^.^.^...^.^.^...^.^.. +............................................................................................................................................. +.^.^.......^.^.^.^.^.^.^...^.....^.^...^.^.^.^.^.^...^...^.^...^.^.........^.....^.^.^.^.....^.^.^.^.^...^.^.^.^.^.^.^.^.^.^...^...^.^...^.^. +.............................................................................................................................................