Created
December 5, 2017 11:18
-
-
Save evilj0e/8450a83dd854a1da56c40d94097f90b8 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
var fs = require('fs'); | |
var text = fs.readFileSync('input.txt', 'utf8'); | |
var data = text.split('\n').map(Number); | |
function count (data) { | |
var counter = 0; | |
for (var i = 0; i < data.length && i >= 0;) { | |
var _i = i; | |
counter += 1; | |
i += data[i]; | |
data[_i] = data[_i] + (data[_i] >= 3 ? -1 : 1); | |
} | |
return counter; | |
} | |
console.log(count(data)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment