const { Glib } = require('../../lib'); const parse = (input) => Glib.fromLines(input).array; const TREE = '#'; const solve = (input, yIncrement, xMultiplier) => { input = parse(input); let xLoc = 0; let treeCount = 0; for (let yLoc = 0; yLoc < input.length; yLoc += yIncrement) { if (input[yLoc][(yLoc * xMultiplier) % input[yLoc].length] === TREE) { treeCount++; } } return treeCount; }; module.exports = { '1': (input) => solve(input, 1, 3), '2': (input) => [[1, 1], [1, 3], [1, 5], [1, 7], [2, 1]] .map(([y, x]) => solve(input, y, x / y)) .reduce((a, b) => a * b), parse, };