-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
38 lines (31 loc) · 925 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import { readFileSync } from 'fs'
import path, { resolve } from 'path'
import { fileURLToPath } from 'url'
async function main() {
if (process.argv.length === 2) {
console.error('Expected an argument.')
console.error('Usage: node . <day>')
process.exit(1)
}
const __filename = fileURLToPath(import.meta.url)
const __dirname = path.dirname(__filename)
const dayNumber = process.argv[2]
const day = `day${dayNumber.padStart(2, '0')}`
const input = readFileSync(
resolve(__dirname, `${day}/input.txt`),
'utf8'
).trimEnd()
try {
const { part1, part2 } = await import(`./${day}/improved.js`)
console.log(part1(input))
console.log(part2(input))
} catch (error) {
if (error.code !== 'ERR_MODULE_NOT_FOUND') {
throw error
}
const { part1, part2 } = await import(`./${day}/index.js`)
console.log(part1(input))
console.log(part2(input))
}
}
main()