Day 9 was interesting in terms of learning. Very satisfying, too.
After reading the problem, I knew I'd be writing a recursive solution. Sure enough, I got an initial one to work with the examples pretty quickly. But when I ran it against my puzzle data, I got the wrong answer. Too high, apparently. How nice. How the heck do I find which data is screwing with my program? Good thing I thought of a
test that helped me find my bug. It was kind of subtle because I didn't think of the nuance until I saw it in the test.
Tip: Just because the sum of all elements is zero, it doesn't mean all elements are zero.
When I realized what the problem was, it was a quick fix to the lambda expression. Part 1 solved.
Part 2 was ridiculously easy to solve, given the way I had set up the semantics of the program. Check this out:
I spent more time writing the tests for it, but not a whole lot more. Done in less than ten minutes.
Then the challenge was to find a way to use tail recursion. Took me longer than it should have but I eventually got that, too. Tail-call recursion isn't the most intuitive thing for me. Need more practice.
Overall, I learned quite a few things with the Day 9 problem. I doubt I can get caught up before Christmas Eve though. Lots of ground to make up. Anyway, it already snowed last night where I am, so I guess most of the people doing AoC got the big snow-making machine in the sky back up and running again.