this post was submitted on 17 Dec 2024
8 points (100.0% liked)
Advent Of Code
920 readers
60 users here now
An unofficial home for the advent of code community on programming.dev!
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.
AoC 2024
Solution Threads
M | T | W | T | F | S | S |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 18 | 20 | 21 | 22 |
23 | 24 | 25 |
Rules/Guidelines
- Follow the programming.dev instance rules
- Keep all content related to advent of code in some way
- If what youre posting relates to a day, put in brackets the year and then day number in front of the post title (e.g. [2024 Day 10])
- When an event is running, keep solutions in the solution megathread to avoid the community getting spammed with posts
Relevant Communities
Relevant Links
Credits
Icon base by Lorc under CC BY 3.0 with modifications to add a gradient
console.log('Hello World')
founded 1 year ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
view the rest of the comments
I'm confused reading the
buildQuine()
method. It reads to me that when you call it from the top level withtop = true
,A0
will be set to 0, and then when we get to the 0 to 8 loop, the 'A' register will be0 * 8 + 0
for the first iteration, and then recurse withtop = false
, but witha0
still 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!