**[Advent of Code 2025][]** *[Code golf style][]* [2022][] [2023][] [2024][] **[2025][]**  > "Advent of Code is an Advent calendar of small programming puzzles for a > variety of skill levels that can be solved in any programming language you > like. People use them as interview prep, company training, university > coursework, practice problems, a speed contest, or to challenge each other. > -- [Eric Wastl][]" [Advent of Code 2025]: https://adventofcode.com/2025 [Code golf style]: https://en.wikipedia.org/wiki/Code_golf [Eric Wastl]: https://was.tl/ [2022]: /aoc/doc/ckout/2022/doc/ [2023]: /aoc/doc/ckout/2023/doc/ [2024]: /aoc/doc/ckout/2024/ [2025]: /aoc/doc/ckout/2025/ # Code (🏌️) ## Day 01 ```py p1, p2, pos, new = 0, 0, 50, 50 for line in open("test.01" if __debug__ else "input.01"): t, q = divmod(int(line[1:]), 100) new += q if line[0] == "R" else -q p2 += t + ((pos > 0 and new <= 0) or new >= 100) pos = new % 100 p1 += pos == 0 print(p1, p2, sep="\n") assert p1 == 3 and p2 == 6 ``` ## Day 02 ```py p1 = p2 = 0 for r in open("test.02" if __debug__ else "input.02").read().split(","): s, e = map(int, r.split("-")) for i in range(s, e + 1): si = str(i) if si[: len(si) // 2] == si[len(si) // 2 :]: p1 += i for j in range(len(si)): if si.count(si[:j]) * j == len(si): p2 += i break print(p1, p2, sep="\n") assert p1 == 1227775554 and p2 == 4174379265 ``` ## Day 03 ```py p = [0, 0] for line in open("test.03" if __debug__ else "input.03").read().splitlines(): for i, n in enumerate([2, 12]): dp = [0] * (n + 1) for j in line: dp = [0] + [max(dp[n + 1], dp[n] * 10 + int(j)) for n in range(n)] p[i] += dp[-1] print(*p, sep="\n") assert p == [357, 3121910778619] ``` ## Day 04 ```py f, n = enumerate(open("test.04" if __debug__ else "input.04")), float("inf") p1, d = 0, [(-1, -1), (-1, 0), (-1, 1), (0, -1), (0, 1), (1, -1), (1, 0), (1, 1)] r0 = r = {(i, j) for i, line in f for j, c in enumerate(line) if c == "@"} while n > (n := len(r)): r = {(x, y) for x, y in r if sum(((x + dx, y + dy) in r) for dx, dy in d) >= 4} print(p1 := len(r0) - len(r)) if not p1 else None print(p2 := len(r0) - len(r)) assert p1 == 13 and p2 == 43 ``` ## Day 05 ```py x, (f, a) = 0, open("test.05" if __debug__ else "input.05").read().split("\n\n") h, *t = sorted(tuple(map(int, i.split("-"))) for i in f.splitlines()) print(p1 := sum(any(j <= int(i) <= k for j, k in [h] + t) for i in a.splitlines())) for i in t: if h[0] <= i[0] <= h[1]: h = (h[0], max(h[1], i[1])) else: x, h = x + h[1] - h[0] + 1, i print(p2 := x + h[1] - h[0] + 1) assert p1 == 3 and p2 == 14 ``` # Stats (⛳) ## LOCs File|blank|comment|code :-------|-------:|-------:|-------: d02.py|0|0|13 d05.py|0|0|10 d01.py|0|0|9 d03.py|0|0|9 d04.py|0|0|8 --------|--------|--------|-------- SUM:|0|0|49 ## Perf ``` 1007 6858 0:00.02 0.01usr 0.01sys 95%CPU 60380kB (0) pypy -O d01.py 19128774598 21932258645 0:00.21 0.20usr 0.00sys 99%CPU 60524kB (0) pypy -O d02.py 17158 170449335646486 0:00.02 0.02usr 0.00sys 96%CPU 60828kB (0) pypy -O d03.py 1518 8665 0:00.19 0.17usr 0.01sys 99%CPU 81952kB (0) pypy -O d04.py 758 343143696885053 0:00.02 0.01usr 0.00sys 100%CPU 60528kB (0) pypy -O d05.py Total: 0.51s ``` !!!BWL: THE BEER-WARE LICENSE (Revision 42) Carlo~~@~~Miron~~.IT~~ wrote this file. As long as you retain this notice you can do whatever you want with this stuff. If we meet some day, and you think this stuff is worth it, you can buy me a beer in return. —㎝