Skip to content

Commit 1dc2866

Browse files
committed
2025: day 7 animation
1 parent d2485ba commit 1dc2866

File tree

7 files changed

+153
-3
lines changed

7 files changed

+153
-3
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@ Puzzle | Stars | Lang
2020
[Day 4: Printing Department](https://adventofcode.com/2025/day/4) | ⭐⭐ | [![Rust](./scripts/assets/rust.png)](src/year2025/day4/day4.rs) [![Python](./scripts/assets/python.png)](src/year2025/day4/day4.py) [![Go](./scripts/assets/go.png)](src/year2025/day4/day4.go)
2121
[Day 5: Cafeteria](https://adventofcode.com/2025/day/5) | ⭐⭐ | [![Rust](./scripts/assets/rust.png)](src/year2025/day5/day5.rs) [![Go](./scripts/assets/go.png)](src/year2025/day5/day5.go)
2222
[Day 6: Trash Compactor](https://adventofcode.com/2025/day/6) | ⭐⭐ | [![Rust](./scripts/assets/rust.png)](src/year2025/day6/day6.rs) [![Rust](./scripts/assets/rust.png)](src/year2025/day6/day6_declarative.rs) [![Python](./scripts/assets/python.png)](src/year2025/day6/day6.py)
23-
[Day 7: Laboratories](https://adventofcode.com/2025/day/7) | ⭐⭐ | [![Rust](./scripts/assets/rust.png)](src/year2025/day7/day7.rs) [![Go](./scripts/assets/go.png)](src/year2025/day7/day7.go)
23+
[Day 7: Laboratories](https://adventofcode.com/2025/day/7) | ⭐⭐ | [![Rust](./scripts/assets/rust.png)](src/year2025/day7/day7.rs) [![Go](./scripts/assets/go.png)](src/year2025/day7/day7.go) [🎁](src/year2025/day7/README.md)
2424

2525
## All years
2626

2727
Calendar | Solutions | Stars | Rust | Python | 🎁
2828
-------- | --------- | ----- | ---- | ------ | --
29-
[Advent of Code 2025](https://adventofcode.com/2025) | [Solutions](src/year2025/README.md) | 14⭐ | 7 | 5 |
29+
[Advent of Code 2025](https://adventofcode.com/2025) | [Solutions](src/year2025/README.md) | 14⭐ | 7 | 5 | 1
3030
[Advent of Code 2024](https://adventofcode.com/2024) | [Solutions](src/year2024/README.md) | 50⭐ | 25 | 11 | 3
3131
[Advent of Code 2023](https://adventofcode.com/2023) | [Solutions](src/year2023/README.md) | 50⭐ | 25 | 10 | 2
3232
[Advent of Code 2022](https://adventofcode.com/2022) | [Solutions](src/year2022/README.md) | 50⭐ | 25 | 18 | 1
@@ -42,6 +42,7 @@ Calendar | Solutions | Stars | Rust | Python | 🎁
4242

4343
Year | Count | Days
4444
---- | ----- | --------------------
45+
2025 | 1 | [7](src/year2025/day7/README.md)
4546
2024 | 3 | [14](src/year2024/day14/README.md) [15](src/year2024/day15/README.md) [16](src/year2024/day16/README.md)
4647
2023 | 2 | [10](src/year2023/day10/README.md) [14](src/year2023/day14/README.md)
4748
2022 | 1 | [17](src/year2022/day17/README.md)

src/year2025/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@ Puzzle | Stars | Lang
1515
[Day 4: Printing Department](https://adventofcode.com/2025/day/4) | ⭐⭐ | [![Rust](../../scripts/assets/rust.png)](day4/day4.rs) [![Python](../../scripts/assets/python.png)](day4/day4.py) [![Go](../../scripts/assets/go.png)](day4/day4.go)
1616
[Day 5: Cafeteria](https://adventofcode.com/2025/day/5) | ⭐⭐ | [![Rust](../../scripts/assets/rust.png)](day5/day5.rs) [![Go](../../scripts/assets/go.png)](day5/day5.go)
1717
[Day 6: Trash Compactor](https://adventofcode.com/2025/day/6) | ⭐⭐ | [![Rust](../../scripts/assets/rust.png)](day6/day6.rs) [![Rust](../../scripts/assets/rust.png)](day6/day6_declarative.rs) [![Python](../../scripts/assets/python.png)](day6/day6.py)
18-
[Day 7: Laboratories](https://adventofcode.com/2025/day/7) | ⭐⭐ | [![Rust](../../scripts/assets/rust.png)](day7/day7.rs) [![Go](../../scripts/assets/go.png)](day7/day7.go)
18+
[Day 7: Laboratories](https://adventofcode.com/2025/day/7) | ⭐⭐ | [![Rust](../../scripts/assets/rust.png)](day7/day7.rs) [![Go](../../scripts/assets/go.png)](day7/day7.go) [🎁](day7/README.md)

src/year2025/day7/README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Day 7
2+
3+
## Part One: beam splitter
4+
5+
[![asciicast](part1.svg)](part1.svg)
6+
7+
## Part Two: quantum tachyon manifold
8+
9+
[![asciicast](part2.svg)](part2.svg)

src/year2025/day7/anim.py

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
#!/usr/bin/env python3
2+
3+
import sys
4+
import time
5+
from copy import deepcopy
6+
from pathlib import Path
7+
8+
RED = "\033[31m"
9+
GREEN = "\033[32m"
10+
LIGHTRED = "\033[91m"
11+
LIGHTGREEN = "\033[92m"
12+
YELLOW = "\033[93m"
13+
BLUE = "\033[94m"
14+
RESET = "\033[0m"
15+
CLEAR = "\033[H\033[2J"
16+
DARK = "\033[1;30m"
17+
18+
19+
START = "S"
20+
SPLITTER = "^"
21+
BEAM = "|"
22+
EMPTY = "."
23+
24+
25+
def show(grid, seconds: float = 0.5, footer=None):
26+
sys.stdout.write(CLEAR)
27+
28+
for row in grid:
29+
color = ""
30+
31+
def pr(new_color: str, cell: str):
32+
nonlocal color
33+
if color != new_color:
34+
color = new_color
35+
sys.stdout.write(color)
36+
sys.stdout.write(cell)
37+
38+
for cell in row:
39+
if cell == EMPTY:
40+
pr(DARK, EMPTY)
41+
elif cell == SPLITTER:
42+
pr(LIGHTGREEN, SPLITTER)
43+
elif cell == BEAM:
44+
pr(YELLOW, BEAM)
45+
elif cell == START:
46+
pr(LIGHTRED, START)
47+
else:
48+
print(cell)
49+
exit()
50+
51+
print(RESET)
52+
53+
if footer is not None:
54+
print()
55+
print(BLUE + f" {footer} ".center(width, "~") + RESET)
56+
57+
time.sleep(seconds)
58+
59+
60+
grid = list(list(line) for line in Path("test.txt").read_text().splitlines())
61+
width = len(grid[0])
62+
height = len(grid)
63+
start_x = grid[0].index("S")
64+
65+
66+
def part1():
67+
show(grid)
68+
69+
beams = set([start_x])
70+
splits = 0
71+
72+
for y in range(1, height):
73+
new_beams = set()
74+
75+
for x in beams:
76+
if grid[y][x] == SPLITTER:
77+
splits += 1
78+
if x > 0:
79+
new_beams.add(x - 1)
80+
if x < width - 1:
81+
new_beams.add(x + 1)
82+
else:
83+
new_beams.add(x)
84+
85+
beams = new_beams
86+
87+
for x in beams:
88+
grid[y][x] = BEAM
89+
90+
show(grid, footer=splits)
91+
92+
93+
def part2(grid, x: int, y: int, count: int):
94+
if y == height:
95+
count += 1
96+
show(grid, 0.25, count)
97+
return count
98+
99+
new_grid = deepcopy(grid)
100+
101+
show(new_grid, 0.005, count)
102+
103+
if grid[y][x] == SPLITTER:
104+
if x > 0:
105+
count = part2(new_grid, x - 1, y, count)
106+
if x < width - 1:
107+
count = part2(new_grid, x + 1, y, count)
108+
else:
109+
new_grid[y][x] = BEAM
110+
count = part2(new_grid, x, y + 1, count)
111+
112+
return count
113+
114+
115+
try:
116+
if len(sys.argv) < 2:
117+
show(grid, 0, "hello")
118+
elif sys.argv[1] == "1":
119+
part1()
120+
elif sys.argv[1] == "2":
121+
part2(grid, start_x, 1, 0)
122+
except KeyboardInterrupt:
123+
pass

src/year2025/day7/make_anim.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
asciinema rec --overwrite part1.cast --window-size "20x20" --command "python3 anim.py 1"
5+
asciinema rec --overwrite part2.cast --window-size "20x20" --command "python3 anim.py 2"
6+
7+
asciinema convert --overwrite -f asciicast-v2 part1.cast part1-v2.cast
8+
asciinema convert --overwrite -f asciicast-v2 part2.cast part2-v2.cast
9+
10+
npm install -g svg-term-cli
11+
12+
svg-term --window --width 20 --height 20 --no-cursor --in part1-v2.cast --out part1.svg
13+
svg-term --window --width 20 --height 20 --no-cursor --in part2-v2.cast --out part2.svg
14+
15+
rm *.cast

src/year2025/day7/part1.svg

Lines changed: 1 addition & 0 deletions
Loading

src/year2025/day7/part2.svg

Lines changed: 1 addition & 0 deletions
Loading

0 commit comments

Comments
 (0)