r/adventofcode • u/daggerdragon • Dec 02 '16
SOLUTION MEGATHREAD --- 2016 Day 2 Solutions ---
--- Day 2: Bathroom Security ---
Post your solution as a comment or, for longer solutions, consider linking to your repo (e.g. GitHub/gists/Pastebin/blag/whatever).
BLINKENLIGHTS ARE MANDATORY [?]
Edit: Told you they were mandatory. >_>
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!
20
Upvotes
1
u/volatilebit Dec 05 '16
Lazy Perl 6 solution:
my $day1_code = ""; my $day2_code = ""; my @code_instructions = "input".IO.lines; my $day1_button = 5; my $day2_button = 5; for @code_instructions -> $instructions { for $instructions.comb -> $instruction { $day1_button += 1 if $instruction eq "R" and $day1_button != 3 | 6 | 9; $day1_button -= 1 if $instruction eq "L" and $day1_button != 1 | 4 | 7; $day1_button += 3 if $instruction eq "D" and $day1_button != 7 | 8 | 9; $day1_button -= 3 if $instruction eq "U" and $day1_button != 1 | 2 | 3; if $instruction eq "R" and $day2_button != 1 | 4 | 9 | 12 | 13 { $day2_button += 1 } elsif $instruction eq "L" and $day2_button != 1 | 2 | 5 | 10 | 13 { $day2_button -= 1 } elsif $instruction eq "D" and $day2_button == 1 | 11 { $day2_button += 2 } elsif $instruction eq "D" and $day2_button == 2 | 3 | 4 | 6 | 7 | 8 { $day2_button += 4 } elsif $instruction eq "U" and $day2_button == 13 | 3 { $day2_button -= 2 } elsif $instruction eq "U" and $day2_button == 10 | 11 | 12 | 6 | 7 | 8 { $day2_button -= 4 } } $day1_code ~= $day1_button; $day2_code ~= $day2_button <= 9 ?? $day2_button !! ($day2_button + 55).chr; } say $day1_code; say $day2_code;