const fs = require('fs') const readline = require('readline'); const readInterface = readline.createInterface({ input: fs.createReadStream('input'), console: false }); // array of arrays of bool. Coordinates are [y][x]. True = tree. let map = []; readInterface.on('line', function(line) { let row = []; line.split('').forEach(function(char) { if (char == '.') { row.push(false); } else if (char == '#') { row.push(true); }; // ignore any other character }); console.log(line); console.log(row); map.push(row); }); readInterface.on('close', function(line) { let treesHit = 0; let x = 0; let y = 0; while (y + 1 < map.length) { x += 3; y += 1; if (x + 1 > map[y].length) { x -= map[y].length; } if (map[y][x]) { treesHit++; } console.log(x, y, map[y][x]); } console.log(treesHit); });