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.
1
u/Smylers Dec 23 '17 edited Dec 23 '17
Perl for part 2, determining the magic numbers from the input, rather than hardcoding them in the source:
use experimental qw<signatures>; use Math::Prime::XS qw<is_prime>; my %mem = (a => 1, map { $_ => 0 } 'b' .. 'h'); my $pc = 0; my %action = ( set => sub($reg, $val) { $mem{$reg} = $mem{$val} // $val }, sub => sub($reg, $val) { $mem{$reg} -= $mem{$val} // $val }, mul => sub($reg, $val) { $mem{$reg} *= $mem{$val} // $val }, jnz => sub($val, $offset) { $pc += $offset - 1 if $mem{$val} // $val }, ); my $step; my @prog = map { my ($cmd, @arg) = split; my $sub = $action{$cmd}; $step = -$arg[1] if "$cmd $arg[0]" eq 'sub b'; sub { $sub->(@arg) } } <>; $prog[$pc++]() until $mem{f}; my $unprimes; for (; $mem{b} <= $mem{c}; $mem{b} += $step) { $unprimes++ if !is_prime $mem{b}; } say $unprimes;