initial upload

This commit is contained in:
2024-12-16 13:11:17 +01:00
parent 33180dc1a3
commit b4997da498
29 changed files with 3778 additions and 0 deletions

7
2023/day01/example.txt Normal file
View File

@ -0,0 +1,7 @@
two1nine
eightwothree
abcone2threexyz
xtwone3four
4nineeightseven2
zoneight234
7pqrstsixteen

27
2023/day01/index.js Normal file
View File

@ -0,0 +1,27 @@
import fs from 'node:fs'
const numberphiles = new Map([
["one", 1],
["two", 2],
["three", 3],
["four", 4],
["five", 5],
["six", 6],
["seven", 7],
["eight", 8],
["nine", 9]
])
fs.readFile('input.txt', ({ encoding: 'utf-8' }), (err, data) => {
const regex1 = /(\d)/gm
// let [first, last] = [matches[0], matches[matches.length-1]]
const regex = /(?=(one|two|three|four|five|six|seven|eight|nine|\d))/gm
let result = 0
for (let line of data.split('\n')) {
const matches = [...line.matchAll(regex)]
let [first, last] = [matches[0][1], matches[matches.length - 1][1]]
first = numberphiles.has(first) ? numberphiles.get(first) : first
last = numberphiles.has(last) ? numberphiles.get(last) : last
result += parseInt(`${first}${last} `)
}
console.log(result)
})

1000
2023/day01/input.txt Normal file

File diff suppressed because it is too large Load Diff