24
src/2025/1/1/index.ts
Normal file
24
src/2025/1/1/index.ts
Normal 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
37
src/2025/1/2/index.ts
Normal 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);
|
||||
}
|
||||
Reference in New Issue
Block a user