feat: FINALLY 2ND PART SOLUTION

This commit is contained in:
2023-12-01 23:25:52 +01:00
parent 2430fa7168
commit 65251c07ad
3 changed files with 42 additions and 6 deletions

View File

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

View File

@@ -5,6 +5,7 @@ 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)
console.log(`${arr} ${line}`)
if (arr.length === 0) return
if (arr.length === 1) {
// lol
@@ -13,11 +14,8 @@ file.forEach((line) => {
if (arr.length >= 2) {
arr = [Number(`${arr[0]}${arr[arr.length - 1]}`)]
}
let sum = 0
arr.forEach(num => sum += num)
array.push(sum)
array.push(...arr)
})
console.log(array.length)
let sum = 0
array.forEach(num => sum += num)

View File

@@ -1 +1,39 @@
console.log('ghjk')
// REALLY UNCLEAN CODE BUT IT WORKS
const regex = /\D/g
const array: Array<number> = []
let file = await (Bun.file('./src/days/1/input.txt')).text()
file = file.replaceAll("twone", "21")
file = file.replaceAll("sevenine", "79")
file = file.replaceAll("oneight", "18")
file = file.replaceAll("threeight", "38")
file = file.replaceAll("nineight", "98")
file = file.replaceAll("fiveight", "58")
file = file.replaceAll("eighthree", "83")
file = file.replaceAll("eightwo", "82")
file = file.replaceAll("one", "1")
file = file.replaceAll("two", "2")
file = file.replaceAll("three", "3")
file = file.replaceAll("four", "4")
file = file.replaceAll("five", "5")
file = file.replaceAll("six", "6")
file = file.replaceAll("seven", "7")
file = file.replaceAll("eight", "8")
file = file.replaceAll("nine", "9")
const fileSplit = file.split("\n");
fileSplit.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]}`)]
}
array.push(...arr)
})
let sum = 0
array.forEach(num => sum += num)
console.log(sum)