From a2f09799e50d360a01931d47c5eef1f698cc857e Mon Sep 17 00:00:00 2001 From: Tyler Beckman Date: Mon, 2 Dec 2024 21:56:05 -0700 Subject: [PATCH] Day 3 --- day3/part1.ts | 8 ++++++++ day3/part2.ts | 10 ++++++++++ 2 files changed, 18 insertions(+) create mode 100644 day3/part1.ts create mode 100644 day3/part2.ts diff --git a/day3/part1.ts b/day3/part1.ts new file mode 100644 index 0000000..279a0bc --- /dev/null +++ b/day3/part1.ts @@ -0,0 +1,8 @@ +export async function solve() { + const input = await Deno.readTextFile("./input.txt"); + let sum = 0; + for (const match of input.matchAll(/mul\((\d{1,3}),(\d{1,3})\)/g)) { + sum += +match[1] * +match[2]; + } + return sum +} \ No newline at end of file diff --git a/day3/part2.ts b/day3/part2.ts new file mode 100644 index 0000000..698a37a --- /dev/null +++ b/day3/part2.ts @@ -0,0 +1,10 @@ +export async function solve() { + const input = await Deno.readTextFile("./input.txt"); + let sum = 0; + for (const part of input.split("do()").slice(1).map(e => e.split("don't()")[0])) { + for (const match of part.matchAll(/mul\((\d{1,3}),(\d{1,3})\)/g)) { + sum += +match[1] * +match[2]; + } + } + return sum +} \ No newline at end of file