18 lines
624 B
JavaScript
18 lines
624 B
JavaScript
|
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);
|