Created
December 4, 2016 08:19
-
-
Save joeinnes/723f194ba7363dbc5eb42c899b8f5b1a to your computer and use it in GitHub Desktop.
Advent Of Code 2016 Day 2 created by joeinnes - https://repl.it/EfFJ/3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const input = `LLLUDRDLLULDUDLLRLUDURULDURRRRLLURLDLDDDULLDDUDLRDLRDUURRDUUDLLRUUDDLULURDLRDUUDUDRURULLLLDRULDDLRDDRDLRDDLURLDDUDLLUUDLRDDDDLULUUURRDLUUDDLULLURRRDULLUDUDRDRDDRLDLLRLRDDDRDLULLUULDLLLRRDDUURUURDLLDRRDDLRULDLLDRLLUDRRDLUUULDLURLLDDURRUULLLLLRLUDLDDLLLURRRDUDULRULULDDLLDLRDDDUULRLRDUURLURRUDDURRUUDUDLDDLDULDDDDDULRULRDLRLDLRDLDDLUDRDUUDLDUDUDLLLRLUUDRUDDDRDRURRLLLDLUULDUULRDLULLUURLDRRRLDRLUDRRURLDULULDRUDDULLLDRDLLULUDDDDRDRULDULRRRRDDRULDLRDU | |
DLDDRRDLLDUURRLULLLLRDRLUDURLDRRDURRRRUUDDUDRRDDDRRLDDLDDLURDLDRLUDULDUDUUDDDLLULRRLLUDULLLUULDDRDDUDUUDULURULULLDRLRUURDRDDLRRUDRUULLLLURRUDRDULDDRURRURLLLLLRLLLRLLUDUDLRDLULDUDLULLLUUDLLDDDUDUDLLRRDLRDLLLRRLRUDRDUDRURLUUURULLDDDDLLURDULURRLLLRLRRULLRRRLUUULLLLRLRDUURRDUURLLLDRDURRRULDDUDRRDLRLDLLRUDDLLUDRLLUUDRLLLLLLUDLURLLRUDRUUUULDLUDULLDDDDRLURUURDDDURRRLRLUDUUDURDDDDRRLRDLURDDLLULDRDDURLLURULUUUUURDUUULDRRLLURRRRRLDDUULLRULLDLDLDLRRRDRLDRUUD | |
RLDRRRURULDLUDLDUDLLDUUURRDUDDURULLRRDDULUUDRRRULRUURRRLUUULRDRUDRRLLRLURDLDRDRDLLUDRUULRUDRUDDRURLRLURRDDRRURUUDRRDDRURURUDUUUDUDRRLRDRUUURLLUUUDLRUUDDRDDDDLDRLRDUDDULDDLRLLRURLLURLDDLDLDDULLDDUUURDLRUDUUDLDURDDRUULDRDDRDDDUUUDRDRDDRRDRRDLRDRURDUDDLUUUDULLUULULULRDRUUDDURURDRRRRLUDLDUDURLDRURDLLUUUDLRRDRRURDDULULURLDUDDLUDLDDLLRLDULLULULURUURLDULUDLLUUDLDDULDRRDDUULLUDLDLLRDRDURDDURDDURLDDURUURLLRURURUDDURRDRLRLDDUUDUULRDLLURRRRULURULDUDUDDUDDRLLLDLURDUURUURLUULRRLDLULDDRLDDUURULURUDRD | |
URLDDRLLRRLDRLLRRURURURDDLRRRUUUURULRRUUDLUDRULLDLRUDDLULRUULDULURLLRLLUDDUDLURDRRRRLURULRURRURRULRRRULDLLDDLRLUDULUUUDDUDDRRDDDDUULRRLDRRULULRDUURRLDDRDULDURUDUDDLDLLURDDLDDRUDUUUDUUURDLDUDUUULLDLRDULRRRDLLURLDLLULRDDULULURLRLUULRLLLDDDUDLLDLURRRULRDUDDLULUDRUDDURULRLRUDDURLLURULLURDRULDUDLDULRRDLDURLUURRDDUDDUDRURUDDURRUUDURUULLLLDDRDDDDDULUUDDURRULLDRRLRRRRRDDRUUDDDURDRDRUDDUULDUDRRDRULUURLURLUDUDULDDRDULDLRUUDLLLRRLRDRDDUUULRDUDLUDLURRDUURDULDRLLDRDULDUDUULRLLDLRLDLUUDLRUULDUUULDLRLRLUULLLLRLRDUDRUUDURLDUDRRURLRUDRRLRDDLRDDLDDUDDDRLRLLRLUUURLURRRLULRLLDRLRDDRRDRL | |
DLLLLLLRLRDRUDLRLLRLDLRURRUURLDLDDDDDUDUULLLLRRLRRDUUDUDLULLRRDULUDLLULURLRULURUULRLURDUDLUDULULUUURLRUDULURULRURULURLRLDRRRRLUDLLDULLDDLLULUURRULRDURDUUDDDURRUDLLLLRLDLUDDULLDUDDURURURRRRULDULULUDDUUDRLRLLLDLLLUUUURUDUUDLDLLRLRDDUULLUURLDDLRRDRLULDLULRULDLDURLULUURRRUDLLRDLUDDULRULULUDDURDLUUURDUUURDUDURLUUDRLUDRULUDDRRDLUUDLLLRDDDDDDLDURDDLDRDLUUDRULLUDRDLDULLULDDRUUDRRLRURRUULLRLRDUUURRDRRDULDDULUUDDURLULRLRURLLRRR` | |
const instructionLines = input.split('\n') | |
const instructions = instructionLines.map((line) => line.split('')) | |
const startNo = 5 | |
const partOneMoveMap = [ | |
{}, | |
{ | |
U: 1, | |
R: 2, | |
D: 4, | |
L: 1 | |
}, { | |
U: 2, | |
R: 3, | |
D: 5, | |
L: 1 | |
}, { | |
U: 3, | |
R: 3, | |
D: 6, | |
L: 2 | |
}, { | |
U: 1, | |
R: 5, | |
D: 7, | |
L: 4 | |
}, { | |
U: 2, | |
R: 6, | |
D: 8, | |
L: 4 | |
}, { | |
U: 3, | |
R: 6, | |
D: 9, | |
L: 5 | |
}, { | |
U: 4, | |
R: 8, | |
D: 7, | |
L: 7 | |
}, { | |
U: 5, | |
R: 9, | |
D: 8, | |
L: 7 | |
}, { | |
U: 6, | |
R: 9, | |
D: 9, | |
L: 8 | |
} | |
] | |
const partTwoMoveMap = [ | |
{}, | |
{ | |
U: 1, | |
R: 1, | |
D: 3, | |
L: 1 | |
}, { | |
U: 2, | |
R: 3, | |
D: 6, | |
L: 2 | |
}, { | |
U: 1, | |
R: 4, | |
D: 7, | |
L: 2 | |
}, { | |
U: 4, | |
R: 4, | |
D: 8, | |
L: 3 | |
}, { | |
U: 5, | |
R: 6, | |
D: 5, | |
L: 5 | |
}, { | |
U: 2, | |
R: 7, | |
D: 10, | |
L: 5 | |
}, { | |
U: 3, | |
R: 8, | |
D: 11, | |
L: 6 | |
}, { | |
U: 4, | |
R: 9, | |
D: 12, | |
L: 7 | |
}, { | |
U: 9, | |
R: 9, | |
D: 9, | |
L: 8 | |
}, { | |
U: 6, | |
R: 11, | |
D: 10, | |
L: 10 | |
}, { | |
U: 7, | |
R: 12, | |
D: 13, | |
L: 10 | |
}, { | |
U: 8, | |
R: 12, | |
D: 12, | |
L: 11 | |
}, { | |
U: 11, | |
R: 13, | |
D: 13, | |
L: 13 | |
} | |
] | |
function partOne () { | |
return instructions.map((line) => { | |
let curNo = startNo | |
line.forEach((move) => { | |
curNo = partOneMoveMap[curNo][move] | |
}) | |
return curNo | |
}).join('') | |
} | |
function partTwo () { | |
return instructions.map((line) => { | |
let curNo = startNo | |
line.forEach((move) => { | |
curNo = partTwoMoveMap[curNo][move] | |
}) | |
return curNo.toString(16) | |
}).join('') | |
} | |
console.log(`Part One: The toilet code is ${partOne()}`) | |
console.log(`Part Two: Actually, the toilet code is ${partTwo()}`) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment