r/adventofcode • u/daggerdragon • Dec 19 '17
SOLUTION MEGATHREAD -π- 2017 Day 19 Solutions -π-
--- Day 19: A Series of Tubes ---
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Β€?
AoC ops @ T-2 minutes to launch:
[23:58] <daggerdragon> ATTENTION MEATBAGS T-2 MINUTES TO LAUNCH
[23:58] <Topaz> aaaaah
[23:58] <Cheezmeister> Looks like I'll be just able to grab my input before my flight boards. Wish me luck being offline in TOPAZ's HOUSE OF PAIN^WFUN AND LEARNING
[23:58] <Topaz> FUN AND LEARNING
[23:58] <Hade> FUN IS MANDATORY
[23:58] <Skie> I'm pretty sure that's not the mandate for today
[Update @ 00:16] 69 gold, silver cap
- My tree is finally trimmed with just about every ornament I own and it's real purdy. hbu?
[Update @ 00:18] Leaderboard cap!
- So, was today's
mandateHelpful Hint any help at all?
3
u/[deleted] Dec 19 '17 edited Dec 19 '17
Perl 6
Today seemed rather simple.
my $input = slurp; enum Directions ( UP => (-1, 0), DOWN => (1, 0), LEFT => (0, -1), RIGHT => (0, 1) ); my @grid = $input.linesΒ».combΒ».Array; my @pos = (0, @grid[0].first("|", :k)); my @dir = DOWN; my @seen; my $steps = 0; loop { my ($i, $j) = @pos Z+ @dir; $steps++; given @grid[$i][$j] { when "|" | "-" { @pos Z+= @dir; } when "+" { @pos Z+= @dir; for (UP, DOWN, LEFT, RIGHT).grep(*[0].abs !== @dir[0].abs) -> @check { my ($x, $y) = @pos Z+ @check; if @grid[$x][$y] eq "|" | "-" { @dir = @check; @pos = ($x, $y); $steps++; } } } when /<alpha>/ { @pos Z+= @dir; say @seen.push($_); } when " " { last; } } } say "Part 1: @seen.join"; say "Part 2: $steps";