I’ve decided to participate in the Advent of Code this year. The idea is that each day two simple puzzles are released, and folks use their favourite programming language to solve them. Folks compete to be the first person to submit a solution (only the first 100 count for points, though). Following Javier Olaechea’s example, I’ll track each day’s solution and post notes here.
I decided to just drop the input in as a string. I thought about encoding it in Base64 or hex, but since it already is a string, why not just be simple about it?
Fortunately, the numbers coïncidentally are acceptable input to
READ, so I was easily able to just read each from the string and let
the standard library do the hard work.
Sum repeatedly, looking for the first repeated sum
My first version (unshown) used a list instead of a vector; this was
inefficient, though, since
LENGTH of a list are O(n), while
LENGTH of a vector are O(1). This didn’t make much
absolute difference (about ⅓ of a second run time), but it made a lot
of relative difference: the less-efficient version took 5¼ times as
long to run. I’m not really going for performance on these solutions,
but in this case I think it’s a good habit.
The hash table is another example of just letting the standard library do the work.