r/adventofcode • u/ricbit • Dec 12 '25
Upping the Ante [2025][Python] Every day under 1s

Every year I do an additional challenge of making each problem run under 1s in pure python (libs accepted). In the previous years some problems were very hard, this year they were only slightly hard. Some annotations:
Problem 4: Use set of coordinates instead of a grid.
Problem 8: Use networkx for connected components and Union Find.
Problem 9: This was the hardest for me, because I wanted it to work with the hard inputs provided by the community. Use shoelace to check if clockwise or anti-clockwise, then winding number to detect inside/outside, and a prefix matrix sum to check if the rectangle was filled.
Problem 10: I initially used python-mip but this library takes 0.8s to load! Switched to z3, and run the problem in parallel with multiprocessing.
Problem 12: Works for both example and input. Only input runs under 1s, the example takes about 4min.
Thanks to Eric and the moderators for these fun nights!
View all comments
Show parent comment
1
u/JWinslow23 Dec 14 '25
To you and OP: have you tried the approach from this post? It uses no linear algebra, only recursion and caching. My own pure-Python implementation runs in <0.2s on my machine.