This commit is contained in:
Nathan Tien You
2025-12-03 16:43:39 +01:00
parent 4eed10da17
commit b86faabc79
17 changed files with 5196 additions and 2 deletions
+31
View File
@@ -0,0 +1,31 @@
import { open } from 'node:fs/promises';
const file = await open('./2025/inputs/3');
let count = 0
for await (const line of file.readLines()) {
count += findPair(line.split("").map(Number))
}
function findPair(numbs: Array<number>) {
let result = ''
for (var i = 12; i > 0; i--) {
const max = findDigit(numbs, i)
const maxIndex = numbs.indexOf(max)
numbs = numbs.slice(maxIndex + 1)
result += max
result
}
return Number(result)
}
function findDigit(numbs: Array<number>, pow: number) {
if (pow != 1) {
numbs = numbs.slice(0, -(pow - 1))
}
const max = Math.max(...numbs)
return max
}
console.log(count)