Skip to content

Instantly share code, notes, and snippets.

@amwmedia
Created December 11, 2017 14:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amwmedia/868d790d0bb50476e88242124ef3f068 to your computer and use it in GitHub Desktop.
Save amwmedia/868d790d0bb50476e88242124ef3f068 to your computer and use it in GitHub Desktop.
Advent Of Code 2017 - Day 5
// 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;
}
// 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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment