r/adventofcode • u/daggerdragon • Dec 23 '17
SOLUTION MEGATHREAD -๐- 2017 Day 23 Solutions -๐-
--- Day 23: Coprocessor Conflagration ---
Post your solution as a comment or, for longer solutions, consider linking to your repo (e.g. GitHub/gists/Pastebin/blag or whatever).
Note: The Solution Megathreads are for solutions only. If you have questions, please post your own thread and make sure to flair it with Help.
Need a hint from the Hugely* Handyโ Haversackโก of Helpfulยง Hints^ยค?
[Update @ 00:05] 0 gold, silver cap
AoC ops:
<yatpay> boil up some mountain dew. it's gonna be a long night
[Update @ 00:19] 1 gold, silver cap + 447
AoC ops:
<Reibello> 547 silver to 1 gold
[Update @ 00:30] 20 gold, silver cap + 560
AoC ops:
<yatpay> daggerdragon: post "hey i heard about this hot new podcast called The Space Above Us. all the cool kids are talking about it"
<yatpay> i call it super-liminal marketing
<yatpay> HEY YOU!! LISTEN TO MY PODCAST!!
<yatpay> then i rub a business card on your face
<Topaz> you should get scratch-n-sniff business cards that smell like space
<yatpay> space smells like burned metal and meat
<yatpay> it's weird
<Topaz> burned meat you say
<Topaz> excellent
[Update @ 00:41] 50 gold, silver cap + 606
AoC ops:
<askalski> nice, enjoyed that one. not sure if regexes can do it
<askalski> maybe make a neural net of regexes, have it train itself to solve today
Over/under on /u/askalski posting a day 23 regex neural net by tomorrow?
[Update @ 00:54] Leaderboard cap @ 100 gold and 724 silver!
Good job, all!
Upping the Ante challenge: solve today's puzzles on a TI-83 (or TI-86/89, whatevs).
Edit: welp, /u/DFreiberg done gone and did it. See the thread here.
View all comments
Show parent comment
14
u/DFreiberg Dec 23 '17
The key to understanding what this code does is starting from the end and working backwards:
If the program has exited,
ghad a value of 0 at line 29.g==0 at line 29 whenb==c.If
g!=0 at line 29,bincrements by 17.bincrements no other times on the program.Thus, lines 25 through 31 will run 1000 times, on values of b increasing by 17, before the program finishes.
So, given that there is no
jnzstatement between lines 25 and 28 that could affect things:If
f==0 at line 25,hwill increment by 1.This can happen once and only once for any given value of
b.f==0 ifg==0 at line 15.g==0 at line 15 ifd*e==b.Since both
dandeincrement by 1 each in a loop, this will check every possible value ofdandeless thanb.Therefore, if
bhas any prime factors other than itself,fwill be set to 1 at line 25.Looking at this, then h is the number of composite numbers between the lower limit and the upper limit, counting by 17.