One of the best coding challenges out there is Advent of Code.
It is a really fun and engaging way to learn a new language or to revisit something that you’ve been away for so long.
In my case it was python.
Python was the language I wrote my PdD in, but at the time I was using version 2.7.
I barely touched python since.
This year I decided to do AoC with python 3.11 and wow, what a difference.
I love this language.
It is so pleasurable to work with.
I’m keeping this entry about the things I’m (re)learning[^day].
Thing that either I didn’t use before or were still absent in 2.7 days.
These things emerged as I progressed through the challenges and compare my code with others[^github].
Around day 18—20 of AoC I stopped participating.
Challenges became more specific about using certain advanced algorithm or data structure and became harder.
As a consequence the time devoted to solving increased.
The issue is that I don’t have that time, but in any case I’m still going through solutions.
The objective is to learn and recall the most of python possible.
And in the end it is all time management.
enumerate
is a very useful command.zip
is also very useful.loadtxt
.for
loops that I’m trying to implement.*[]
and [::1]
numpy, re, math
and don’t try to reinvent the algorithms.functools.cmp_to_key
works but I still find it a bit cumbersome to use.numpy.where(condition)
in 2D matrices gives two arrays with the indicies of the entries.numpy.argwhere(condition)
and .tolist()
. The former case needs a lot of massaging to get a tuple of coordinates back[^npargwhere].scipy.spatial.distance
has methods for spatial distance calculations that are very useful, namely pdist
, cdist
, and squareform
splitlines
can shorten the loading of the inputs… something in the line of open(0).read().strip().splitlines()
to read from standard in.numba
This is exciting.numpy
.[^day] And we are only at day 20 at the time of writing. I’ll update this as AoC progresses.
[^github] My AoC repository contains my daily solutions in case you want to check my progress.
[^npargwhere] https://numpy.org/doc/stable/reference/generated/numpy.argwhere.html