Added day 2
This commit is contained in:
parent
8b208ef94f
commit
ecb8b376a4
5
day02/input.txt
Normal file
5
day02/input.txt
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
LLULLLRLDLLLRLUURDDLRDLDURULRLUULUDDUDDLLLURRLDRRLDRRRLDUDLRDLRRDLLDUDUDUDRLUDUUDLLLRDURUDUULUDLRDUUUDUUDURLDUULLRDLULDUURUDRDDLDRLURLRURRDUURLRLUURURUUULLRLLULRUURLULURDLLRRUDLUDULDRDRLRULUURRDRULLRUUUDLRLDLUURRRURDLUDDRRUDRLUDRDLLLLLRULLDUDRLRRDDULDLRUURRRRRLDLDLRDURDRUUURDLRDDDDULURRRRDUURLULLLDLRULRDULRUDLRRLRDLLRLLLUDDLRDRURDDLLLLDUDRDLRURRDLRDDDLDULDRLRULUUDRRRUUULLLURRDDUULURULDURRLLULLDRURUUULRLRDRRUDRDRRDURRUUUULDRDDDUDLDDURLLRR
|
||||||
|
LDLRRRUURDLDDRLRRDLLULRULLLUDUUDUDLRULLDRUDRULLDULURDRDDLRURDDULLLLDLRDRDRDDURLURLURLUDRDDRDULULUDDRURRDLLDUURDRDDLRLLURRDLRDDULDLULURDRDLUDRRUUDULLULURRDUDRUUUDRULDLDURLRRUDURLDLRRUURRRURDLUDRLDUDRRUDUURURUDDUUDRDULRDLUDRRRLDRURLLRDDDLUDRDUDURDDDRRDDRRRLLRRDDLDDLRUURRURDLLDRLRRDLLUDRRRURURLRDRLLRLRLRULLRURLDLRRULLRRRDULUUULDRDLLURDDLDLRDRLUUDLLUDDLDRRLDLRUDRUDLLUURLLULURUDUDRLULLUDRURDDLDLDDUDLRDDRRURLRLLUDDUDRUURRURRULDRLDDRLLRRLDDURRDLDULLLURULLLRUURLRRRRUUULRLLLURRLRLRUDRDUUUDUUUDDLULLDLLLLDLDRULDRUUULDDDLURLDLRLULRUDDDDURDDLU
|
||||||
|
RURLURRDLDULLULDDDLRUULLUURLRUDRUDRRUDDLDDDDRRDLRURLRURLDDDUDDUURRDRULDRRRULRDRDDLRUDULRLURDUUDRRLDLRDRURDLDRRRRDRURUUDDDLLRDRDUDUDUDLLULURULRRLRURUULUULDDDDURULRULLRUDUURLURDUDLUDLUDRLLDUUDUULRLRLUUDRDULDULRURDRRRULRUDLRURDDULUDULLRLRURURUULLULDRURLLRRUUDDUUURRDLURUURULRDRRDDUDULRDDLUDLURURUURDRULLRDDLLRDDLDRDUDRRDLUURRLRLUURRULUDURLDDRLLURRDDDLDDRURULLDDRLUDDLRLURDUDULLRDULLLDLLUDDRUDRUDDUUDRDRULRL
|
||||||
|
RLRDRDULULUDLUDRDRLUDLDLLUDURULDDDUDLRURLLRLRLDLDRLDURDLRRURLULLULURLLDRRDRLUDRLRDLLULRULURRURURUULRDUDLLRDLRRRRRLUURDRRRDLRUDLLDLLDLRUUUDLLLDDDLRDULLRUUDDRLDDURRRDLRLRLDDDDLRDRULLUURUUDRRLLRLLRDDLLRURRRRDRULRRLLRLLLRLDRRLDDDURRURLDURUURRLRLRLDRURULLRLRUDLDUURDLLRLDLURUUUDLLRDRDDDDDDRLDRRRLRRRRURUDLDDRDLLURUDLRRLDDDLUDUDUULRDULULUDDULUUDLLLLRLDDUUULRLRDULURDURRRURRULURRRDRDLDDURDLURUDURRRDDRLRLUDLUDDLUULLDURLURDDUDDLRUUUDRLLDRURL
|
||||||
|
ULUDLLUDDULRUURDRURDUDUDLUURDDDRRLUDURURDRURRLDRDURLRLLRRDDRRDRRRUULURUDURUDULRRRRDDLDURRLRRDUDDDRLLLULDRLRLURRDUURDURRRURRDLUDUDDRLDLURRRDDRLLRDRDDRDURRRRLURRLUDDURRULRUDUDULDRUDDRULLUUULDURRRLDRULLURULLRUDLDUDDLDULDLUUDRULULDLLDRULLRUULDUDUUDRLRRLDLUULUDLLDDRLRRDDLLURURDULRRDDRURDRLRLULDLDURULLUUUDURURDLDUDDDDUUULUDLUURRULLDLRLURDLURLRLDDURRLDDRRRDUUULLUULDLLDLLDDRLRRUDLULDRLULDULULRRLRULUUURURUUURDUUDDURLLUDDRLRDDLUURRUULRDLDDRLULUULRDRURLUURDRDUURUDLRR
|
27
day02/part1.js
Normal file
27
day02/part1.js
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
var fs = require("fs");
|
||||||
|
var input = fs.readFileSync("input.txt").toString().replace(/\r/g, "");
|
||||||
|
var moves = {
|
||||||
|
U: -3,
|
||||||
|
D: 3,
|
||||||
|
L: -1,
|
||||||
|
R: 1
|
||||||
|
};
|
||||||
|
var prev = 5;
|
||||||
|
var locations = input.split("\n").slice(0, -1).map(function(curr, i, arr){
|
||||||
|
return curr.split("").reduce(function(pos, char){
|
||||||
|
var newpos = pos + moves[char];
|
||||||
|
if(Math.abs(moves[char]) == 1){
|
||||||
|
if(Math.abs((newpos - 1)%3 - (pos - 1)%3) == 1){
|
||||||
|
prev = newpos;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
if(newpos >= 1 && newpos <= 9){
|
||||||
|
prev = newpos;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return prev;
|
||||||
|
}, prev);
|
||||||
|
});
|
||||||
|
|
||||||
|
console.log(locations.join(""));
|
35
day02/part2.js
Normal file
35
day02/part2.js
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
var board = [
|
||||||
|
{"0": 1},
|
||||||
|
{"-1": 2, "0": 3, "1": 4},
|
||||||
|
{"-2": 5, "-1": 6, "0": 7, "1": 8, "2": 9},
|
||||||
|
{"-1": "A", "0": "B", "1": "C"},
|
||||||
|
{"0": "D"}
|
||||||
|
];
|
||||||
|
var moves = {
|
||||||
|
U: [-1, 0],
|
||||||
|
D: [1, 0],
|
||||||
|
L: [0, -1],
|
||||||
|
R: [0, 1],
|
||||||
|
}
|
||||||
|
var pos = [2, -2];
|
||||||
|
var locations = [];
|
||||||
|
var fs = require("fs");
|
||||||
|
var input = fs.readFileSync("input.txt").toString().replace(/\r/g, "");
|
||||||
|
input.split("\n").slice(0, -1).forEach(function(line){
|
||||||
|
if(line){
|
||||||
|
line.split("").forEach(function(char){
|
||||||
|
if(char){
|
||||||
|
var move = moves[char];
|
||||||
|
var newpos = pos.map((a, x)=>(a + move[x]));
|
||||||
|
if(board[newpos[0]]){
|
||||||
|
if(board[newpos[0]][newpos[1]]){
|
||||||
|
pos = newpos;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
console.log(board[pos[0]][pos[1]]);
|
||||||
|
locations.push(board[pos[0]][pos[1]]);
|
||||||
|
});
|
||||||
|
console.log(locations.join(""));
|
Loading…
x
Reference in New Issue
Block a user