-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
38 lines (34 loc) · 1008 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
const fs = require('fs');
const inputs = process.argv.slice(2)
const day = Number(inputs[0])
const path = day < 10 ? `./day0${day}` : `./day${day}`
const fileText = fs.readFileSync(path + '/input.txt').toString().replace(/\r/g, '')
const text = () => {
if ([4, 6, 16, 19, 20, 22].indexOf(day) !== -1) {
return fileText
.split('\n\n')
.filter(s => s.length > 0)
} else {
return fileText
.split('\n')
.filter(s => s.length > 0)
}
}
const solver = require(path + '/solver')
const runPart = part => {
const answer = solver.solve(text(), part)
const expected = solver.expected(part)
if (answer === expected) {
console.log(`Correct: ${day} part ${part}: ${answer}`)
} else {
console.log(`Incorrect: ${day} part ${part}: ${answer} - expected ${expected}`)
}
}
if (day === 25) {
runPart(1)
} else if (inputs.length === 1) {
runPart(1)
runPart(2)
} else {
runPart(Number(inputs[1]))
}