Had very little time to work on CL stuff today, so I decided to do the first puzzle in this year's Advent of Code. It's simple: add all of the numbers in the provided input file together. Perfect for working on my skills in a new language.
I began by searching for how to read in plain text files into Lisp. Found it asked on Stack Overflow. It turns out there's a function (or maybe it's a macro?) called with-open-file
. I didn't copy and paste it directly, but I basically just wrote it as it was answered.
Then I wrote a function to convert this list of integers represented as strings to a list that only contained the +
sign initially. Then a function that I could run to execute all of this.
Kaboom: it didn't work. So I tinkered around a whole bunch and ended up with some really ugly code full of bad practices (global variable when another way would have probably been better, using nconc
for appending items to that global list). But it worked after maybe the 15th or 20th time running it. And it's 50 minutes until midnight, so this will have to do for today.
Code is available in code/Dec2018/7/aoc-2018-1a.lisp
.