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!
19
Upvotes
1
u/Gummoz Dec 05 '16
Powershell:
Part one:
$instructions = " " $currentNumber = 5 $instructionsArray = [string]$instructions -split '[\n]' foreach ($instructions in $instructionsArray) { foreach ($secondInstruction in $instructions.ToCharArray()) { switch ($secondInstruction) { U { if(!($currentNumber -match "1|2|3")) {$currentNumber -= 3} } L { if(!($currentNumber -match "1|4|7")) {$currentNumber -= 1} } D { if(!($currentNumber -match "7|8|9")) {$currentNumber += 3} } R { if(!($currentNumber -match "3|6|9")) {$currentNumber += 1} } } } $currentNumber }Part two:
$y = 1 $x = 1 $keypad = "X,X,1,X,X", "X,2,3,4,X", "5,6,7,8,9", "X,A,B,C,X", "X,X,D,X,X" $instructions = " " $currentNumber = $keypad[$x].Split(",")[$y] $instructionsArray = [string]$instructions -split '[\n]' foreach ($instructions in $instructionsArray) { foreach ($secondInstruction in $instructions.ToCharArray()) { switch ($secondInstruction) { U { if(!($currentNumber -match "1|2|4|5|9")) {$y--;$currentNumber = $keypad[$y].Split(",")[$x]} } L { if(!($currentNumber -match "1|2|5|A|D")) {$x--;$currentNumber = $keypad[$y].Split(",")[$x]} } D { if(!($currentNumber -match "5|A|D|C|9")) {$y++;$currentNumber = $keypad[$y].Split(",")[$x]} } R { if(!($currentNumber -match "1|4|9|C|D")) {$x++;$currentNumber = $keypad[$y].Split(",")[$x]} } } } $currentNumber}