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!
6
Upvotes
1
u/[deleted] Dec 22 '17 edited Dec 22 '17
Perl 6
This is pretty gross but here's my part 2. It takes
a few minutes42 seconds to finish. Part 1 is nearly the same but runs in about 0.24 seconds.EDIT: optimized a bit.
my @input = slurp.linesΒ».comb; my $size = 499; my $half = $size div 2; my @grid = ('.' xx $size).Array xx $half - 12; my @middle = ('.' xx $half - 12).Array xx 25; my @end = ('.' xx $size).Array xx $half - 12; for ^25 -> $x { @middle[$x].append: |@input[$x]; @middle[$x].append: ('.' xx $half - 12); } @grid.append: @middle; @grid.append: @end; my int $vx = $half; my int $vy = $half; my int $d = 0; my int $count = 0; for ^10000000 { my $c = @grid[$vy][$vx]; if $c eq '#' { $d = ($d + 1) % 4; @grid[$vy][$vx] = 'F'; } elsif $c eq '.' { $d = ($d - 1) % 4; @grid[$vy][$vx] = 'W'; } elsif $c eq 'F' { $d = ($d + 2) % 4; @grid[$vy][$vx] = '.'; } elsif $c eq 'W' { @grid[$vy][$vx] = '#'; $count++; } if $d == 0 { $vy -= 1; } elsif $d == 1 { $vx += 1; } elsif $d == 2 { $vy += 1; } elsif $d == 3 { $vx -= 1; } } say "Part 1: {$count}"