solution: 2025/3
Signed-off-by: Alix von Schirp <github@avonschirp.bootmedia.de>
This commit is contained in:
19
src/2025/3/1/index.ts
Normal file
19
src/2025/3/1/index.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
export default async function runner(inputPath: string){
|
||||
const input = (await Bun.file(inputPath).text()).trimEnd();
|
||||
|
||||
let sum = 0;
|
||||
|
||||
input.split("\n").forEach(line => {
|
||||
let compare = 0;
|
||||
if(line.trim() === "") return;
|
||||
for(let i = 0; i<line.length; i++){
|
||||
for(let j = i+1; j<line.length; j++) {
|
||||
let wip = parseInt(`${line[i]}${line[j]}`)
|
||||
if(wip > compare) compare = wip;
|
||||
}
|
||||
}
|
||||
sum += compare;
|
||||
})
|
||||
|
||||
console.log(sum);
|
||||
}
|
||||
43
src/2025/3/2/index.ts
Normal file
43
src/2025/3/2/index.ts
Normal file
@@ -0,0 +1,43 @@
|
||||
export default async function runner(inputPath: string){
|
||||
const input = (await Bun.file(inputPath).text()).trimEnd();
|
||||
|
||||
let sum = 0;
|
||||
|
||||
input.split("\n").forEach(line => {
|
||||
let compare = 0;
|
||||
if(line.trim() === "") return;
|
||||
|
||||
let removals = line.length-12;
|
||||
const result: number[] = [];
|
||||
for(let i = 0; i < line.length; i++){
|
||||
const pointed = parseInt(line[i]!);
|
||||
if(removals === 0 || result.length === 0) {
|
||||
result.push(pointed);
|
||||
continue;
|
||||
}
|
||||
while (removals > 0 && result.length > 0 && result[result.length - 1]! < pointed) {
|
||||
result.pop();
|
||||
removals--;
|
||||
}
|
||||
result.push(pointed);
|
||||
}
|
||||
|
||||
const final = result.length===12 ? result.join("") : result.map((value, index) => [index, value])
|
||||
.sort((a, b) => {
|
||||
if (b[1] !== a[1]) {
|
||||
return b[1]! - a[1]!;
|
||||
}
|
||||
return a[0]! - b[0]!;
|
||||
})
|
||||
.slice(0, 12)
|
||||
.sort((a, b) => a[0]! - b[0]!)
|
||||
.map(value => value[1])
|
||||
.join("");
|
||||
|
||||
sum += parseInt(final)
|
||||
})
|
||||
|
||||
console.log()
|
||||
console.log()
|
||||
console.log(sum);
|
||||
}
|
||||
Reference in New Issue
Block a user