adventofcode-2017/day05/part2.js

17 lines
310 B
JavaScript
Raw Normal View History

2017-12-06 13:40:43 +00:00
var offsets = require("fs").readFileSync("input.txt").toString().split("\n").filter((a)=>(a)).map((a)=>(parseInt(a)));
var pc = 0;
var i = 0;
while(offsets[pc] != null){
i++;
var oldpc = pc;
pc += offsets[pc];
if(offsets[oldpc] >= 3){
offsets[oldpc]--;
}
else{
offsets[oldpc]++
}
}
console.log(i);