Advent of Code 2023- Day 8

This is a thread to discuss Day 8

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

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

I found Part 1 the easiest puzzle so far this year

Part 2 will probably be MUCH harder :slight_smile:

[edit] I have the correct answer to Part 2 but not quite worked out how to get it programmatically!
[edit2] I have code to produce the correct answer but I'm not sure why it works as I can't reconcile it to what Wikipedia says in the clue

image

Clue

It's to do with with finding least common multiple
Least common multiple - Wikipedia
Factorizing - #11 by cymplecy
See

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

I can't access your project. It says it's unshared.

Somehow the last letter of the filename got cut off when I copy/pasted it

It's ok now

Didn't you want that project hidden under the "Clue" thingy?

No ta
Just need to hide plain text spoilers - the link to the project is there for people to look at if/when they want to

I, too, found the answer to part 2. It’s a huge number, impossible to calculate with brute force.

Fortunately, for each ??A start node, the period of repetition is exactly the same as the number of steps for reaching the first ??Z end node. The answer is the Least Common Multiple of all periods.

Code for calculating LCM
(recursive, of course :smirk:)