Created
December 3, 2024 05:04
-
-
Save bluepichu/8f9c3dd4a449a7753ac499253ca0881c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Advent, f, fm, chr, ord, isDigit } from "advent"; | |
import { Set, Map } from "immutable"; | |
const { compute, computeCheck } = await Advent({ day: 3 }); | |
compute(2, async (input) => { | |
const data = input.parse(f.str()); | |
const regex = /mul\((\d+),(\d+)\)|do\(\)|don't\(\)/g; | |
let ok = true; | |
let ans = 0; | |
for (const match of data.matchAll(regex)) { | |
console.log(match); | |
if (match[0] === "do()") { | |
ok = true; | |
} else if (match[0] === "don't()") { | |
ok = false; | |
} else if (ok) { | |
const [_, a, b] = match; | |
ans += parseInt(a) * parseInt(b); | |
} | |
} | |
return ans; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment