diff --git a/src/2025/2/1/index.ts b/src/2025/2/1/index.ts new file mode 100644 index 0000000..a192896 --- /dev/null +++ b/src/2025/2/1/index.ts @@ -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); +} diff --git a/src/2025/2/2/index.ts b/src/2025/2/2/index.ts new file mode 100644 index 0000000..4745a0d --- /dev/null +++ b/src/2025/2/2/index.ts @@ -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