Stream: advent of code

Topic: 2023 Day 9


view this post on Zulip Oskar Hahn (Dec 09 2023 at 06:17):

https://github.com/ostcar/aoc2023/blob/main/days/day09.roc

I did not get the problem

view this post on Zulip Johan Lindskogen (Dec 09 2023 at 06:24):

https://github.com/lindskogen/advent-of-code-2023/blob/main/day09/main.roc

view this post on Zulip Luke Boswell (Dec 09 2023 at 09:32):

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

view this post on Zulip Ryan Bates (Dec 09 2023 at 10:26):

Here's mine for day 9. https://github.com/ryanb/advent-2023-roc/blob/main/day09/main.roc

Thought about difficulty

A potential optimization

view this post on Zulip Fabian Schmalzried (Dec 09 2023 at 20:23):

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.

view this post on Zulip timotree (Dec 11 2023 at 07:50):

Ryan Bates said:

Reply

view this post on Zulip timotree (Dec 11 2023 at 07:53):

My day 9: https://github.com/timotree3/aoc2023/blob/main/roc/day9.roc

view this post on Zulip Ryan Bates (Dec 11 2023 at 18:50):

Reply to timotree

view this post on Zulip Norbert Hajagos (Feb 08 2024 at 18:30):

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

x0=0x_0 = 0 xi=xi1+yix_i = - x_{i-1} + y_i

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