8
🖥️ - 2024 DAY 17 SOLUTIONS - 🖥️
(programming.dev)
An unofficial home for the advent of code community on programming.dev! Other challenges are also welcome!
Advent of Code is an annual Advent calendar of small programming puzzles for a variety of skill sets and skill levels that can be solved in any programming language you like.
Everybody Codes is another collection of programming puzzles with seasonal events.
Solution Threads
| M | T | W | T | F | S | S |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | 6 | 7 |
| 8 | 9 | 10 | 11 | 12 |
Icon base by Lorc under CC BY 3.0 with modifications to add a gradient
console.log('Hello World')
I'm confused reading the
buildQuine()method. It reads to me that when you call it from the top level withtop = true,A0will be set to 0, and then when we get to the 0 to 8 loop, the 'A' register will be0 * 8 + 0for the first iteration, and then recurse withtop = false, but witha0still ending up 0, causing infinite recursion.Am I missing something?
I got it to work with a check that avoids the recursion if the last state's A register value is the same as the new state's value.
Oh, good catch. That's certainly the case if an initial value of 0 correctly generates the required value of the quine. As I'd already started running some code against the live data that's what I tested against, and so it's only when I just tested it against the example data that I saw the problem.
I have changed the for-loop to read
for (var a in (top ? 1 : 0).to(8))for maximum terseness :-)That still works for the example and my live data, and I don't think there should be a valid solution that relies on the first triplet being 0. Thanks for your reply!