-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexecute.js
27 lines (20 loc) · 890 Bytes
/
execute.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
'use strict';
const fs = require('fs');
console.log('\n\n ------------------------------ Script start ------------------------------ \n');
const [year, day, useExampleFlag] = process.argv.slice(2);
const basePath = `./20${year}/${day}`;
const solver = require(`${basePath}/solution.js`);
if (solver.solve) {
solver.solve();
}
if (typeof solver.main === 'function') {
const inputFile = ['e', 'example'].includes(useExampleFlag) ? 'example.txt' : 'actual.txt';
const inputFilePath = `${basePath}/${inputFile}`;
const inputExists = fs.existsSync(inputFilePath);
const input = inputExists ? fs.readFileSync(inputFilePath, 'utf-8') : null;
const start = Date.now();
const result = solver.main(input);
const inputToPrint = inputExists ? inputFile : 'hardcoded input';
console.log(`\nresult for ${inputToPrint}: (took ${Date.now() - start} ms)`);
console.log(result);
}