Advent Of Code 2017 - Day 5
// Day 5 - Challenge #2
// input is an array of integers
function escapeHops2(input) {
let hops = 0;
for (let pos = 0; pos < input.length;) {
const prevPos = pos;
pos += input[pos];
hops += 1;
input[prevPos] += (input[prevPos] >= 3 ? -1 : 1);
}
return hops;
}
// Day 5 - Challenge #1
// input is an array of integers
function escapeHops(input) {
let hops = 0;
for (let pos = 0; pos < input.length;) {
const prevPos = pos;
pos += input[pos];
hops += 1;
input[prevPos]++;
}
return hops;
}