Created
December 3, 2016 20:28
-
-
Save flupe/5e0ab25a8864860b3fa9caea040b8122 to your computer and use it in GitHub Desktop.
advent of code day 2
This file contains hidden or 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
| let fs = require('fs') | |
| let code = [] | |
| let pad = [ | |
| [0, 0, 1, 0, 0], | |
| [0, 2, 3, 4, 0], | |
| [5, 6, 7, 8, 9], | |
| [0, 'A', 'B', 'C', 0], | |
| [0, 0, 'D', 0, 0] | |
| ] | |
| let data = fs.readFileSync('./data/2A.txt') | |
| .toString() | |
| .trim() | |
| .split('\n') | |
| .reduce((pos, input) => { | |
| let [x, y] = input.split('').reduce((pos, move) => { | |
| let [x, y] = pos | |
| if(move == 'U') y-- | |
| if(move == 'R') x++ | |
| if(move == 'D') y++ | |
| if(move == 'L') x-- | |
| if (x < 0 || x > 4 || y < 0 || y > 4 || pad[y][x] == 0) | |
| return pos | |
| return [x, y] | |
| }, pos) | |
| code.push(pad[y][x]) | |
| return [x, y] | |
| }, [0, 2]) | |
| console.log(code.join('')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment