advent-of-code/2022/10/index2.js
2022-12-10 09:28:13 -08:00

22 lines
565 B
JavaScript

const fs = require('fs/promises');
(async () => {
const input = await fs.readFile("./input.txt", 'utf8');
const simplified = input.replace(/noop/g, '0').replace(/addx (.*)/g, '0\n$1').split("\n").map(s => parseFloat(s));
const cycleValues = simplified.reduce((vals, change, i) => {
vals.push(vals[i] + change);
return vals;
}, [1]);
console.log(cycleValues);
while(cycleValues.length) {
const row = cycleValues.splice(0, 40);
console.log(row.map((pos, i) =>
pos >= i - 1 && pos <= i + 1 ? "X" : "."
).join(""))
}
})();