feat: day 1 part 1

This commit is contained in:
2023-12-01 19:12:12 +01:00
parent d96200aba3
commit 2430fa7168
3 changed files with 27 additions and 2 deletions

1
2023/.gitignore vendored
View File

@@ -170,3 +170,4 @@ dist
# IntelliJ based IDEs
.idea
input.txt

View File

@@ -12,7 +12,7 @@ program
const file = dirs.find((dir) => dir.name === `${option.part}.ts`);
if (file) {
logger('success', `Running day ${day}`)
await import(`./days/${file.name}/${option.part}`);
await import(`./days/${day}/${option.part}.ts`);
} else {
logger('error', `Day ${day} part ${option.part} not found!`);
}

View File

@@ -1 +1,25 @@
console.log('asdf')
// REALLY UNCLEAN CODE BUT IT WORKS
const regex = /\D/g
const array: Array<number> = []
const file = (await (Bun.file('./src/days/1/input.txt')).text()).split('\n')
file.forEach((line) => {
let arr = Array.from(line.replace(regex, '')).map(Number)
if (arr.length === 0) return
if (arr.length === 1) {
// lol
arr = [Number(`${arr[0]}${arr[0]}`)]
}
if (arr.length >= 2) {
arr = [Number(`${arr[0]}${arr[arr.length - 1]}`)]
}
let sum = 0
arr.forEach(num => sum += num)
array.push(sum)
})
console.log(array.length)
let sum = 0
array.forEach(num => sum += num)
console.log(sum)