https://github.com/ostcar/aoc2023/blob/main/days/day09.roc
I did not get the problem
https://github.com/lindskogen/advent-of-code-2023/blob/main/day09/main.roc
This is my solution for Day 9.
I thought this was quite nice to do with Roc, recursion and pattern matching are really nice to work with.
performance
Here's mine for day 9. https://github.com/ryanb/advent-2023-roc/blob/main/day09/main.roc
Thought about difficulty
A potential optimization
https://github.com/FabHof/aoc-2023/blob/main/day9/main.roc
Was pretty easy. My current solution basically does both Part 1 and 2 twice, one for each output, but it takes only a few seconds to run, so it's good enough. I start to like that you are not going to know how hard it will be.
Ryan Bates said:
Reply
My day 9: https://github.com/timotree3/aoc2023/blob/main/roc/day9.roc
Reply to timotree
I have found out something very cool about part2!
(It's been monts, so I'll not put this under a spoiler)
You don't need to first calculate the difference lists all the way until zeroes to start calculating the prediction per line "from the tip of the piramid back to the base of it". You just need to sum up the first numbers in the difference lists as they appear with alternating sign. So for the test input below, sum up the numbers in inside the stars (the first number is positive) :
*10* 13 16 21 30 45
*3* 3 5 9 15
*0* 2 4 6
*2* 2 2
*0* 0
The prediction is +10-3+0-2+0 = 5.
Because the algorith for the i-th line prediction is
where y_i is the i-th line's first number
You can find my solution here: https://github.com/HajagosNorbert/advent-of-code-2023/blob/main/day09.roc#L37-L44
Last updated: Jul 06 2025 at 12:14 UTC