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