This commit is contained in:
2024-12-06 10:26:09 +01:00
parent 49a3571c09
commit 6201805a0a
3 changed files with 37 additions and 0 deletions
+25
View File
@@ -0,0 +1,25 @@
import fs from "node:fs"
const input = fs.readFileSync("./2024/inputs/3").toString()
const groups = Array.from(input.matchAll(/(?<dont>don't\(\))|(?<do>do\(\))|(?<mul>mul\((\d{1,3}),(\d{1,3})\))/gm))
let enabled = true
let result = 0
for (const g of groups) {
if (!g.groups) {
continue
}
if (g.groups["dont"]) {
enabled = false
continue
}
if (g.groups["do"]) {
enabled = true
continue
}
if (enabled) {
result += (Number(g[4]) * Number(g[5]))
}
}
console.log(result)