Created
December 11, 2017 14:21
-
-
Save amwmedia/868d790d0bb50476e88242124ef3f068 to your computer and use it in GitHub Desktop.
Advent Of Code 2017 - Day 5
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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