mirror of
https://github.com/SrIzan10/adventofcode.git
synced 2026-06-27 18:52:20 +00:00
feat: day 1 part 1
This commit is contained in:
1
2023/.gitignore
vendored
1
2023/.gitignore
vendored
@@ -170,3 +170,4 @@ dist
|
||||
|
||||
# IntelliJ based IDEs
|
||||
.idea
|
||||
input.txt
|
||||
@@ -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!`);
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
Reference in New Issue
Block a user