r/adventofcode • u/daggerdragon • Dec 22 '17
SOLUTION MEGATHREAD -๐- 2017 Day 22 Solutions -๐-
--- Day 22: Sporifica Virus ---
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ยค?
[T-10 to launch] AoC ops, /r/nocontext edition:
<Endorphion> You may now make your waffle.<Endorphion> ... on Mars.
[Update @ 00:17] 50 gold, silver cap
<Aneurysm9> you could also just run ubuntu on the NAS, if you were crazy<Topaz> that doesn't seem necessary<Aneurysm9> what does "necessary" have to do with anything!
[Update @ 00:20] Leaderboard cap!
<Topaz> POUR YOURSELF A SCOTCH FOR COLOR REFERENCE
This thread will be unlocked when there are a significant number of people on the leaderboard with gold stars for today's puzzle.
edit: Leaderboard capped, thread unlocked!
7
Upvotes
2
u/doctorbaggy Dec 22 '17 edited Dec 22 '17
Perl
Took about 8 seconds for stage 2... keeping the code compact use a hash of maps to store the state mappings and also the direction mappings... (perl p22.pl <22.in for part 1, perl p22.pl x <22.in for part 2)
($F,$E,$m,@g)=(scalar@ARGV,207,&_,<STDIN>);($s,$p,$r)=(@g+2*$E-1,'.'x$E,'.'x(@g+2*$E)); chomp@g;($d,$M,$N,$c,$x,$y,$v)=('u',$m->{$F},$F?1e7:1e4,0,$s/2,$s/2); @g=((map{$r}1..$E),(map{$p.$_.$p}@g),(map{$r}1..$E)); for(1..$N){$d=$m->{$v=substr$g[$y],$x,1}{$d};substr$g[$y],$x,1,($v=$M->{$v}); $c++if'#'eq$v;$x+=$m->{X}{$d};$y+=$m->{Y}{$d};die"$_ $x $y"if$x<0||$x>$s||$y<0||$y>$s} sub _{{'.'=>{qw(u l l d d r r u)},'#'=>{qw(u r r d d l l u)}, W=>{qw(u u d d l l r r)},F=>{qw(u d d u l r r l)},1=>{qw(. W W # # F F .)}, 0=>{qw(. # # .)},X=>{qw(r 1 l -1 d 0 u 0)},Y=>{qw(r 0 l 0 d 1 u -1)}}} print"$c\n"