Files
adventofcode2024/day3/pt2.ts
Joey Eamigh b606826561 day3
2024-12-03 20:09:32 -05:00

13 lines
469 B
TypeScript

const input = await Bun.file('./inputs/day3').text();
const regex = /(?<instruction>do|don't)\(\)|mul\((?<first>\d+)\,(?<second>\d+)\)/g;
let enabled = true;
let total = 0;
input.matchAll(regex).forEach(({ groups }) => {
if (groups!.instruction === 'do') enabled = true;
else if (groups!.instruction === "don't") enabled = false;
else if (enabled) total += Number(groups!.first) * Number(groups!.second);
});
console.log(`sum of mult with do/don't: ${total}`);