adventofcode-2016/day18/part2.js

8 lines
508 B
JavaScript
Raw Permalink Normal View History

2016-12-19 00:27:20 +00:00
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);