Skip to content

Instantly share code, notes, and snippets.

@bluepichu
Created December 3, 2024 05:04
Show Gist options
  • Save bluepichu/8f9c3dd4a449a7753ac499253ca0881c to your computer and use it in GitHub Desktop.
Save bluepichu/8f9c3dd4a449a7753ac499253ca0881c to your computer and use it in GitHub Desktop.
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