diff --git a/2023/src/days/1/1.ts b/2023/src/days/1/1.ts index 3965acb..0f90123 100644 --- a/2023/src/days/1/1.ts +++ b/2023/src/days/1/1.ts @@ -1,8 +1,10 @@ // REALLY UNCLEAN CODE BUT IT WORKS +import getInput from "../../util/getInput.ts" + const regex = /\D/g const array: Array = [] -const file = (await (Bun.file('./src/days/1/input.txt')).text()).split('\n') +const file = (await getInput(1)).split('\n') file.forEach((line) => { let arr = Array.from(line.replace(regex, '')).map(Number) console.log(`${arr} ${line}`) diff --git a/2023/src/days/1/2.ts b/2023/src/days/1/2.ts index e435c45..f9b49d7 100644 --- a/2023/src/days/1/2.ts +++ b/2023/src/days/1/2.ts @@ -1,8 +1,10 @@ +import getInput from "../../util/getInput.ts" + // REALLY UNCLEAN CODE BUT IT WORKS const regex = /\D/g const array: Array = [] -let file = await (Bun.file('./src/days/1/input.txt')).text() +let file = await getInput(1) file = file.replaceAll("twone", "21") file = file.replaceAll("sevenine", "79") file = file.replaceAll("oneight", "18") diff --git a/2023/src/util/getInput.ts b/2023/src/util/getInput.ts new file mode 100644 index 0000000..6811f64 --- /dev/null +++ b/2023/src/util/getInput.ts @@ -0,0 +1,3 @@ +export default async function getInput(day: number) { + return await (Bun.file(`./src/days/${day}/input.txt`)).text() +} \ No newline at end of file