Signed-off-by: Alix von Schirp <github@avonschirp.bootmedia.de>
This commit is contained in:
2025-12-02 18:42:45 +01:00
parent d68bc92f2e
commit a77081ef4e
2 changed files with 42 additions and 0 deletions

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

@@ -0,0 +1,17 @@
export default async function runner(inputPath: string){
const input = (await Bun.file(inputPath).text()).trimEnd();
let sum = 0;
input.split(",").forEach(segment => {
if(segment.trim() === "") return;
const [low, high] = segment.split("-").map(value => parseInt(value));
if(low === undefined || high === undefined) return;
for(let i = low; i<=high; i++){
const stringNum: string = `${i}`;
if(stringNum.substring(0, stringNum.length/2) === stringNum.substring(stringNum.length/2)) sum += i;
}
})
console.log(sum);
}

25
src/2025/2/2/index.ts Normal file
View File

@@ -0,0 +1,25 @@
export default async function runner(inputPath: string){
const input = (await Bun.file(inputPath).text()).trimEnd();
let sum = 0;
input.split(",").forEach(segment => {
if(segment.trim() === "") return;
const [low, high] = segment.split("-").map(value => parseInt(value));
if(low === undefined || high === undefined) return;
for(let i = low; i<=high; i++){
const stringNum: string = `${i}`;
sum += helper(stringNum)
}
})
console.log(sum);
}
function helper(stringNum: string){
for(let j = 0; j<stringNum.length/2; j++) {
if(stringNum.match(/^(\d+)\1+$/gm)) return parseInt(stringNum);
}
return 0;
}