Blog 2019/12/1
<- previous | index | next ->
I thought I'd use Advent of Code as a way to get some more Clojure experience!
https://adventofcode.com/2019/day/1
Part 1 is straightforward. There is a file with a list of integers (one per line). We need to parse them in as a list of ints, map a formula across them, then sum to a single value.
In part 2, we have to recursively calculate the fuel needed by the fuel, and the fuel needed by that fuel, and so on.
This recursion terminates because the floor / integer truncation eventually returns zero (or the forumla ends up returning a negative value).
This sounds similar to the square root / fixed point stuff from SICP: https://www.lvguowei.me/post/sicp-goodness-sqrt/
We rename mass-to-fuel
to mass-to-fuel-naive
and then implement a new, recursive mass-to-fuel
.