From d68bc92f2e00290e99cedf75d827401508c148e7 Mon Sep 17 00:00:00 2001 From: Alix von Schirp Date: Mon, 1 Dec 2025 16:20:15 +0100 Subject: [PATCH] 2025/1 Signed-off-by: Alix von Schirp --- src/2025/1/1/index.ts | 24 ++++++++++++++++++++++++ src/2025/1/2/index.ts | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 src/2025/1/1/index.ts create mode 100644 src/2025/1/2/index.ts diff --git a/src/2025/1/1/index.ts b/src/2025/1/1/index.ts new file mode 100644 index 0000000..32e8878 --- /dev/null +++ b/src/2025/1/1/index.ts @@ -0,0 +1,24 @@ +export default async function runner(inputPath: string){ + const input = (await Bun.file(inputPath).text()).trimEnd(); + + let pos = 50; + + let pass = 0; + input.split("\n").forEach(line => { + if(line.trim() === "") return; + if(line[0] === "L") { + const num = parseInt(line.substring(1)); + pos -= num; + } + if(line[0] === "R") { + const num = parseInt(line.substring(1)); + pos += num; + } + + while(pos<0) pos += 100; + if (pos > 99) pos = pos % 100; + if(pos === 0) pass++; + }) + + console.log(pass); +} diff --git a/src/2025/1/2/index.ts b/src/2025/1/2/index.ts new file mode 100644 index 0000000..0385009 --- /dev/null +++ b/src/2025/1/2/index.ts @@ -0,0 +1,37 @@ +export default async function runner(inputPath: string){ + const input = (await Bun.file(inputPath).text()).trimEnd(); + + let pos = 50; + + let pass = 0; + input.split("\n").forEach(line => { + let oldpos = pos; + if(line.trim() === "") return; + const num = parseInt(line.substring(1)); + const turns = Math.floor(num/100); + const amount = num % 100; + + pass += turns; + + if(line[0] === "L") { + pos -= amount; + } + if(line[0] === "R") { + pos += amount; + } + + + + if(pos === 0) pass++; + while(pos<0) { + pos += 100; + if(oldpos !== 0) pass++; + } + if (pos > 99) { + pos = pos % 100; + if(oldpos !== 0) pass++; + } + }) + + console.log(pass); +}