17 lines
310 B
JavaScript
17 lines
310 B
JavaScript
|
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);
|