Signed-off-by: Alix von Schirp <github@avonschirp.bootmedia.de>
This commit is contained in:
2025-12-01 16:20:15 +01:00
parent 6336bec39b
commit d68bc92f2e
2 changed files with 61 additions and 0 deletions

24
src/2025/1/1/index.ts Normal file
View File

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

37
src/2025/1/2/index.ts Normal file
View File

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