This commit is contained in:
Tim Stallard 2017-12-08 09:29:31 +00:00
parent 7124a52027
commit e9e4c7a9cc
Signed by: Tim
GPG Key ID: AAE46381AF6A3FE8
3 changed files with 1030 additions and 0 deletions

1000
day08/input.txt Normal file

File diff suppressed because it is too large Load Diff

13
day08/part1.js Normal file
View File

@ -0,0 +1,13 @@
var regs = {};
var lines = require("fs").readFileSync("input.txt").toString().split("\n").filter((a)=>(a));
getreg = (reg)=>((reg in regs) ? (regs[reg]) : (0));
for(var line of lines){
var condition = new RegExp("[a-z]+ (inc|dec) (-?)[0-9]+ if (.*)").exec(line)[3].replace(/^([a-z]+) (.*)/, "getreg('$1') $2");
if(eval(condition)){
if(!(line.split(" ")[0] in regs)){
regs[line.split(" ")[0]] = 0;
}
regs[line.split(" ")[0]] += ((line.split(" ")[1] == "inc") ? 1 : -1) * parseInt(line.split(" ")[2]);
}
}
console.log(Math.max.apply(null, Object.keys(regs).map((a)=>(regs[a]))));

17
day08/part2.js Normal file
View File

@ -0,0 +1,17 @@
var regs = {};
var lines = require("fs").readFileSync("input.txt").toString().split("\n").filter((a)=>(a));
getreg = (reg)=>((reg in regs) ? (regs[reg]) : (0));
var max = 0;
for(var line of lines){
var condition = new RegExp("[a-z]+ (inc|dec) (-?)[0-9]+ if (.*)").exec(line)[3].replace(/^([a-z]+) (.*)/, "getreg('$1') $2");
if(eval(condition)){
if(!(line.split(" ")[0] in regs)){
regs[line.split(" ")[0]] = 0;
}
regs[line.split(" ")[0]] += ((line.split(" ")[1] == "inc") ? 1 : -1) * parseInt(line.split(" ")[2]);
if(regs[line.split(" ")[0]] > max){
max = regs[line.split(" ")[0]];
}
}
}
console.log(max);