Day 01 Part 01

This commit is contained in:
Skye Ewers 2023-12-01 21:13:58 +01:00
commit cb140cac39
7 changed files with 1253 additions and 0 deletions

30
01/index.ts Normal file
View file

@ -0,0 +1,30 @@
const fs = require('fs').promises;
const input: string = (await fs.readFile('./input.txt')).toString()
console.log("Solution first part: " + partOne())
function partOne(): string {
let digits = []
for (const line of input.split('\n')) {
let first = undefined
let last = undefined
for (const char of line) {
const digit = parseInt(char)
if (!Number.isNaN(digit)) {
if (first === undefined) {
first = digit
}
last = digit
}
}
digits.push(parseInt(`${first}${last}`))
}
let sum = digits.reduce((acc, item) => {
return acc += item
})
return `${sum}`
}
function partTwo() {}