Skip to content

Instantly share code, notes, and snippets.

@evilj0e
Created December 5, 2017 11:18
Show Gist options
  • Select an option

  • Save evilj0e/8450a83dd854a1da56c40d94097f90b8 to your computer and use it in GitHub Desktop.

Select an option

Save evilj0e/8450a83dd854a1da56c40d94097f90b8 to your computer and use it in GitHub Desktop.

Revisions

  1. evilj0e created this gist Dec 5, 2017.
    20 changes: 20 additions & 0 deletions aoc-5.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,20 @@
    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));