Day 18
This commit is contained in:
parent
0bd0b89e91
commit
6f45c42781
7
day18/part1.js
Normal file
7
day18/part1.js
Normal file
@ -0,0 +1,7 @@
|
||||
nextline = (line)=>(line.split("").map((char, i, arr)=>([arr[i-1], arr[i], arr[i+1]]).map((char)=>(char ? char : ".")).join("")).map((str)=>(["^^.", ".^^", "..^", "^.."].indexOf(str) != -1)).map((trap)=>(trap ? "^" : ".")).join(""));
|
||||
|
||||
var lines = [".^^^^^.^^^..^^^^^...^.^..^^^.^^....^.^...^^^...^^^^..^...^...^^.^.^.......^..^^...^.^.^^..^^^^^...^."];
|
||||
while(lines.length < 40){
|
||||
lines.push(nextline(lines[lines.length - 1]));
|
||||
}
|
||||
console.log(lines.map((line)=>(line.replace(/\^/g, ""))).join("").length);
|
7
day18/part2.js
Normal file
7
day18/part2.js
Normal file
@ -0,0 +1,7 @@
|
||||
nextline = (line)=>(line.split("").map((char, i, arr)=>([arr[i-1], arr[i], arr[i+1]]).map((char)=>(char ? char : ".")).join("")).map((str)=>(["^^.", ".^^", "..^", "^.."].indexOf(str) != -1)).map((trap)=>(trap ? "^" : ".")).join(""));
|
||||
|
||||
var lines = [".^^^^^.^^^..^^^^^...^.^..^^^.^^....^.^...^^^...^^^^..^...^...^^.^.^.......^..^^...^.^.^^..^^^^^...^."];
|
||||
while(lines.length < 400000){
|
||||
lines.push(nextline(lines[lines.length - 1]));
|
||||
}
|
||||
console.log(lines.map((line)=>(line.replace(/\^/g, ""))).join("").length);
|
Loading…
x
Reference in New Issue
Block a user