This commit is contained in:
Joey Eamigh
2024-12-03 20:09:32 -05:00
parent 7ca9b1d3f6
commit b606826561
15 changed files with 1285 additions and 3 deletions

9
day3/pt1.ts Normal file
View File

@@ -0,0 +1,9 @@
const input = await Bun.file('./inputs/day3').text();
const regex = /mul\((?<first>\d+)\,(?<second>\d+)\)/g;
const total = input
.matchAll(regex)
.map(({ groups }) => Number(groups!.first) * Number(groups!.second))
.reduce((curr, acc) => curr + acc);
console.log(`sum of mult: ${total}`);

12
day3/pt2.ts Normal file
View File

@@ -0,0 +1,12 @@
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}`);