advent of code 2025 in ts and nix

feat: add day two ts solution

dunkirk.sh bc42c17b f743cc4e

verified
Changed files
+59 -1
shared
ts
-1
index.ts
···
-
console.log("Hello via Bun!");
+1
shared/02/input.txt
···
+
26803-38596,161-351,37-56,9945663-10044587,350019-413817,5252508299-5252534634,38145069-38162596,1747127-1881019,609816-640411,207466-230638,18904-25781,131637-190261,438347308-438525264,5124157617-5124298820,68670991-68710448,8282798062-8282867198,2942-5251,659813-676399,57-99,5857600742-5857691960,9898925025-9899040061,745821-835116,2056-2782,686588904-686792094,5487438-5622255,325224-347154,352-630,244657-315699,459409-500499,639-918,78943-106934,3260856-3442902,3-20,887467-1022885,975-1863,5897-13354,43667065-43786338
+58
ts/02/index.ts
···
+
const file = await Bun.file("../../shared/02/input.txt").text();
+
+
const ranges: { start: number; end: number }[] = file
+
.split(",")
+
.map((range) => {
+
const splitRange = range.split("-");
+
return {
+
start: Number.parseInt(splitRange[0] as string, 10),
+
end: Number.parseInt(splitRange[1] as string, 10),
+
};
+
});
+
+
(() => {
+
let count = 0;
+
+
ranges.forEach((range) => {
+
for (let i = range.start; i <= range.end; i++) {
+
const numberString = i.toString();
+
+
if (numberString.length % 2 === 1) continue;
+
+
const firstHalf = numberString.substring(
+
0,
+
(numberString.length + 1) / 2,
+
);
+
const secondHalf = numberString.substring(numberString.length / 2);
+
+
if (firstHalf === secondHalf) count += i;
+
}
+
});
+
+
console.log("part 1:", count);
+
})();
+
+
(() => {
+
let count = 0;
+
+
ranges.forEach((range) => {
+
for (let i = range.start; i <= range.end; i++) {
+
const numberString = i.toString();
+
+
for (let j = 1; j <= Math.floor(numberString.length / 2); j++) {
+
if (numberString.length % j !== 0) continue;
+
+
const chunk = numberString.slice(0, j);
+
+
let testString = "";
+
for (let k = 0; k < numberString.length / j; k++) testString += chunk;
+
if (testString === numberString) {
+
count += i;
+
break;
+
}
+
}
+
}
+
});
+
+
console.log("part 2:", count);
+
})();