daily pastebin goal
4%
SHARE
TWEET

Untitled

a guest Dec 7th, 2017 44 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var fs = require('fs');
  2. var text = fs.readFileSync('input.txt', 'utf8');
  3. var data = text.split('\n').map(Number);
  4.  
  5. function count (data) {
  6.     var counter = 0;
  7.  
  8.     for (var i = 0; i < data.length && i >= 0;) {
  9.         var _i = i;
  10.        
  11.         counter += 1;
  12.         i += data[i];
  13.  
  14.         data[_i] = data[_i] + (data[_i] >= 3 ? -1 : 1);
  15.     }
  16.  
  17.     return counter;
  18. }
  19.  
  20. console.log(count(data));
RAW Paste Data
Top