From a77081ef4e06b2c86313f833d18d96d74edd8335 Mon Sep 17 00:00:00 2001 From: Alix von Schirp Date: Tue, 2 Dec 2025 18:42:45 +0100 Subject: [PATCH] 2025/2 Signed-off-by: Alix von Schirp --- src/2025/2/1/index.ts | 17 +++++++++++++++++ src/2025/2/2/index.ts | 25 +++++++++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 src/2025/2/1/index.ts create mode 100644 src/2025/2/2/index.ts diff --git a/src/2025/2/1/index.ts b/src/2025/2/1/index.ts new file mode 100644 index 0000000..a192896 --- /dev/null +++ b/src/2025/2/1/index.ts @@ -0,0 +1,17 @@ +export default async function runner(inputPath: string){ + const input = (await Bun.file(inputPath).text()).trimEnd(); + + let sum = 0; + + input.split(",").forEach(segment => { + if(segment.trim() === "") return; + const [low, high] = segment.split("-").map(value => parseInt(value)); + if(low === undefined || high === undefined) return; + for(let i = low; i<=high; i++){ + const stringNum: string = `${i}`; + if(stringNum.substring(0, stringNum.length/2) === stringNum.substring(stringNum.length/2)) sum += i; + } + }) + + console.log(sum); +} diff --git a/src/2025/2/2/index.ts b/src/2025/2/2/index.ts new file mode 100644 index 0000000..4745a0d --- /dev/null +++ b/src/2025/2/2/index.ts @@ -0,0 +1,25 @@ +export default async function runner(inputPath: string){ + const input = (await Bun.file(inputPath).text()).trimEnd(); + + let sum = 0; + + input.split(",").forEach(segment => { + if(segment.trim() === "") return; + const [low, high] = segment.split("-").map(value => parseInt(value)); + if(low === undefined || high === undefined) return; + for(let i = low; i<=high; i++){ + const stringNum: string = `${i}`; + + sum += helper(stringNum) + } + }) + + console.log(sum); +} + +function helper(stringNum: string){ + for(let j = 0; j