Added day 7

This commit is contained in:
Tim Stallard 2016-12-07 09:08:00 +00:00
parent 9dd903ceac
commit 580d527c1b
3 changed files with 2008 additions and 0 deletions

2000
day07/input.txt Normal file

File diff suppressed because it is too large Load Diff

4
day07/part1.js Normal file
View File

@ -0,0 +1,4 @@
abba=(s)=>(s.split("").reduce((a, b, i, c)=>((i < 3) ? (a) : (((c[i] == c[i - 3]) && (c[i - 1] == c[i - 2]) && (c[i] != c[i - 1])) || a)), false));
var input = require("fs").readFileSync("input.txt").toString().replace(/\r/g, "");
var ips = input.split("\n").filter((s)=>(abba(s))).filter((s)=>(!s.match(/\[[^\]]+\]/g).reduce((a, b)=>(abba(b) || a), false)));
console.log(ips.length)

4
day07/part2.js Normal file
View File

@ -0,0 +1,4 @@
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)