solution(partial): 2025/6/1

Signed-off-by: Alix von Schirp <github@avonschirp.bootmedia.de>
This commit is contained in:
2025-12-07 17:32:58 +01:00
parent 57f78bc4f6
commit 2cb5c1ea8a
2 changed files with 40 additions and 0 deletions

40
src/2025/6/1/index.ts Normal file
View File

@@ -0,0 +1,40 @@
export default async function runner(inputPath: string) {
const input = (await Bun.file(inputPath).text()).trimEnd();
let sum = 0;
const splittedOutput = input.split("\n").map(value => {
return value.trim().split(/([\d\s]+)\s/gm);
})
const transposedInput: string[][] = [];
for(let i = 0; i < splittedOutput[0]!.length; i++){
const transInput: string[] = [];
splittedOutput.forEach(line => {
transInput.push(line[i]!)
})
transposedInput.push(transInput)
}
transposedInput.forEach(value => {
let work = 0;
for(let i = 0; i < value.length - 1; i++){
if(work === 0 && value[value.length-1] === "*") work = 1;
const val = parseInt(value[i]!)
switch (value[value.length-1]){
case "+":
work += val;
break;
case "*":
work *= val;
break;
}
}
sum += work;
})
console.log(sum)
}

0
src/2025/6/2/index.ts Normal file
View File