Advent of Code 2023 - Day 9

This is a thread to discuss Day 9

https://adventofcode.com/2023/day/9

REMEMBER!
It is VERY important NOT to write any public spoilers :slight_smile:
ALWAYS keep spoiler stuff hidden inside one of these

Summary

This text will be hidden

which you can obtain by clicking on the gear icon

image

Good luck :slight_smile:
FYI one of the features of Advent of Code is that we all get given different inputs so our answers will be different.
The examples are all the same but each of us gets different inputs for us to solve

Been busy today doing real world stuff but easiest puzzle so far for me

It took 5 mins to alter code for Part 1 into Part 2 :slight_smile:

https://snap.berkeley.edu/snap/snap.html#present:Username=cymplecy&ProjectName=aoc23Day9&editMode

[edit] Link fixed

The link doesn’t work for meIt does now..
But indeed, it’s a simple puzzle, especially if you use recursion. :wink:

part 1

part 2

simply reverse each input line:

Part 1 was honestly pretty easy, and I was actually surprised at how fast it ran due to a bunch of recursion (although I figured out how to find the pattern using hyperblocks).

Part 1



advent of code 2023 script pic (4)

I was very glad to know that I didn't need to remove the last element from the list. Of course I did make an optimization, instead of going until all the differences are 0, it just goes until they're equal. I decided to do this because if they're equal, the difference will be 0. It just removes an extra unnecessary step.

Part 2

I just modified my code from part 1 to work for part 2. Glad it was such a simple edit.


Project link

Snap! Build Your Own Blocks

An ultra-compact version of part 2


(part 1 solution differs insofar as REVERSE OF is to be omitted)