19 lines
443 B
TypeScript
19 lines
443 B
TypeScript
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>) {
|
|
const max = Math.max(...numbs.toSpliced(-1, 1))
|
|
const maxIndex = numbs.indexOf(max)
|
|
|
|
const digit = Math.max(...numbs.slice(maxIndex + 1))
|
|
return (max * 10) + digit
|
|
}
|
|
|
|
console.log(count) |