Advent of Code 2020 1-5
9/11/2024
Preamble
I've started doing some of the older (year 2020) advent of code problems for fun / preparation for this years AoC. Here are my solutions to days 1-5. I've also added notes as to what makes a solution interesting
Day 1
Notes
Racket has nice syntax for handling streams. In this case, note the
stream for combinations, in-combinations
Day 2
Notes
There are a few nice racket-y things here:
-
the higher-order function
try
which wraps a function, tries to run it, and if it fails it moves on. This is also available in R's purrr package assafely
-
(list _ ... rule-char)
- This matches against a list, doesn't care what the first n items
are, but matches the final item in the list. Racket also has the
special form
list*
which lets you treat the end of the list as a variable.
- This matches against a list, doesn't care what the first n items
are, but matches the final item in the list. Racket also has the
special form
Day 3
Notes
There is a neat little syntax-saver with the #:do
keyword.
Day 4
Notes
- There is the equivalent of python's nested list / dict comprehension
in
structured-passports
valid?
takes a hash-table and a list of validator functions.andmap
is pretty useful for these algorithmic-type questions.match
is always nice to use. This isn't doing anything crazy, but I enjoy the clarity when reading it.
Day 5
Notes
This could also be done using functions that co-recursively call each other, but my train stop is coming up 😁