solution(partial): 2025/6/1
Signed-off-by: Alix von Schirp <github@avonschirp.bootmedia.de>
This commit is contained in:
40
src/2025/6/1/index.ts
Normal file
40
src/2025/6/1/index.ts
Normal 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
0
src/2025/6/2/index.ts
Normal file
Reference in New Issue
Block a user