This repository has been archived on 2026-05-07. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
advent-of-coding-2024/Day 03/Part 1/index.ts
2024-12-09 08:10:43 +01:00

24 lines
457 B
TypeScript

import fs from 'node:fs';
export default function runner(input: string) {
fs.readFile(`./${input}`, 'utf8', (err, data) => {
if (err) throw err;
let count = 0;
const regex = /mul\((?<a>\d{1,3}),(?<b>\d{1,3})\)/gm;
let m;
while ((m = regex.exec(data)) !== null) {
if (m.index === regex.lastIndex) {
regex.lastIndex++;
}
count += parseInt(m[1]??"")*parseInt(m[2]??"")
}
console.log(count)
})
}