From 88756bdce73754a6afdf6994ed6d5cf98f13c018 Mon Sep 17 00:00:00 2001 From: Alix von Schirp Date: Tue, 11 Nov 2025 04:41:56 +0100 Subject: [PATCH] 2015/2 --- src/2015/2/1/index.ts | 21 +++++++++++++++++++++ src/2015/2/2/index.ts | 24 ++++++++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 src/2015/2/1/index.ts create mode 100644 src/2015/2/2/index.ts diff --git a/src/2015/2/1/index.ts b/src/2015/2/1/index.ts new file mode 100644 index 0000000..7042da9 --- /dev/null +++ b/src/2015/2/1/index.ts @@ -0,0 +1,21 @@ +export default async function runner(inputPath: string) { + const input = await Bun.file(inputPath).text(); + + let totalArea = 0; + + input.split("\n").forEach(line => { + if (line.trim() === '') return; + + const [l, w, h]: number[] = line.split("x") as unknown as number[]; + + if(!l || !w || !h) return; + const s1 = l*w; + const s2 = w*h; + const s3 = l*h; + + const a = 2*s1 + 2*s2 + 2*s3 + Math.min(s1, s2, s3); + totalArea += a; + }) + + console.log(totalArea) +} diff --git a/src/2015/2/2/index.ts b/src/2015/2/2/index.ts new file mode 100644 index 0000000..f2f11e9 --- /dev/null +++ b/src/2015/2/2/index.ts @@ -0,0 +1,24 @@ +export default async function runner(inputPath: string) { + const input = await Bun.file(inputPath).text(); + + let totalArea = 0; + + input.split("\n").forEach(line => { + if (line.trim() === '') return; + + const [l, w, h]: number[] = line.split("x") as unknown as number[]; + + if(!l || !w || !h) return; + const c1 = 2*l+2*w; + const c2 = 2*w+2*h; + const c3 = 2*l+2*h; + + + const v = l*w*h; + + const a = Math.min(c1, c2, c3) + v; + totalArea += a; + }) + + console.log(totalArea) +}