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); +}