Advent of Code 2025 Day 9— Python
Marketing Pitch and Impressions#
Python is a programming language that lets you work quickly and integrate systems more effectively.
I estimate that 97.23% of all Advent of Code solutions are written in Python. It is a super legible, super productive language with enormous libraries that everyone uses. You’ve probably used it yourself. It’s pretty much the standard scripting language in use today. It’s really easy to get stuff done. The downside is that in most cases, that stuff will run more slowly than in a compiled language.
Visual Studio Code support is excellent.
The Code#
The code is very legible, and super easy to write and debug, but this malleability comes at a cost. A roughly equivalent Kotlin implementation takes ~70ms to run on my machine, but the Python implementation takes 2,700ms, mostly in part 2.
After reading in the points, part 1 is a basic 1-liner to maximise the area between any two points. The generator expressions work really well here, and we don’t generate huge lists of pairs of points to get the job done.
For part 2, we find the largest rectangle that doesn’t intersect with any of the line segments that form the boundary defined by the red tiles.
| |
Install Python and run#
If you really don’t have it on your machine, you can download from python.org.
# You probably have this already
# Execute the code
python3 d09.py