Yan Cui
I help clients go faster for less using serverless technologies.
ps. look out for all my other solutions for Advent of Code challenges here.
Day 25
See details of the challenge here.
Today’s input looks like this:
cpy a d
cpy 7 c
cpy 362 b
inc d
dec b
jnz b -2…
At last, we’re at the end of this year’s Advent of Code challenges, and today’s challenge is another twist of the assembunny code we’ve seen a few times this year, most recently on Day 23.
Ad before, let’s define the instruction set as a union type and make short work of the parsing the input file.
One notable difference to today’s challenge though is that we’re no longer interested in the value of the registers but the output from executing the program.
So instead of returning the registers we’ll use a sequence comprehension to return the output values as an infinite, and lazy sequence instead.
(ps. I initially wrote the execute function with a nested recursive function, but on second thought the problem feels more concisely expressed as a while loop so I rewrote it as such)
To wrap up today’s challenge (part 2 just requires you to click a link to wrap up your AOC journey for another year) we need to find the first value of n that will yield pairs of [ 0, 1 ] indefinitely. Of course you can’t be sure that the pattern repeats indefinitely without deeper understanding of the pattern of change in the register values (perhaps it’d be a better approach rather than the trial-and-error route I have gone with). I have gone with 1000 values all following that pattern = repeating indefinitely, but turns out the answer is the same even when you use Seq.take 10.
So there it is folks, another year and another set of wonderfully enjoyable challenges. With you all a happy new year and see you soon!
Links
- Day 25 challenge description
- Advent of Code 2015
- Solution for Day 24
- Solution for Day 23
- All my F# solutions for Advent of Code
- Github repo
Whenever you’re ready, here are 3 ways I can help you:
- Production-Ready Serverless: Join 20+ AWS Heroes & Community Builders and 1000+ other students in levelling up your serverless game. This is your one-stop shop for quickly levelling up your serverless skills.
- I help clients launch product ideas, improve their development processes and upskill their teams. If you’d like to work together, then let’s get in touch.
- Join my community on Discord, ask questions, and join the discussion on all things AWS and Serverless.
Pingback: F# Weekly #1, 2017 – New Year Edition – Sergey Tihon's Blog