adventofcode-2016/day07/part2.js

5 lines
410 B
JavaScript
Raw Normal View History

2016-12-07 09:08:00 +00:00
aba=(s)=>(s.split("").reduce((a, b, i, c)=>{if(((c[i] == c[i - 2]) && (c[i] != c[i - 1]))){a.push(c[i-1] + c[i] + c[i-1]);} return a;}, []));
var input = require("fs").readFileSync("input.txt").toString().replace(/\r/g, "");
var ips = input.split("\n").filter((s)=>(aba(s.split(/\[[^\]]+\]/g).join("")).reduce((a, b)=>((s.match(/\[[^\]]+\]/g).join("").indexOf(b) != -1) || a), false)))
console.log(ips.length)