-
Notifications
You must be signed in to change notification settings - Fork 0
/
ProblemManager.js
47 lines (38 loc) · 1.11 KB
/
ProblemManager.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
39
40
41
42
43
44
45
46
47
module.exports = function () {
var Problem = function (number, result) {
this.number = number;
this.result = result;
};
var runProblem = function (problemNumber) {
var start,
end;
problemNumber = getPaddedProblemNumber(problemNumber);
start = new Date(),
console.log("Running problem " + problemNumber + "...");
console.log("----------------------------\n");
try {
getResult(problemNumber);
end = new Date();
console.log("\n----------------------------");
console.log("Time taken: " + (end - start) + " milliseconds");
}
catch (e) {
if (e.code==="MODULE_NOT_FOUND")
console.log("Problem not solved yet!");
}
};
var getPaddedProblemNumber = function (problemNumber) {
while (problemNumber.length < 3)
problemNumber = "0" + problemNumber;
return problemNumber;
};
var getResult = function (problemNumber) {
var paddedProblemNumber = getPaddedProblemNumber(problemNumber);
return require("./Solutions/Problem" + paddedProblemNumber).run();
};
return {
Problem: Problem,
runProblem: runProblem,
getResult: getResult
};
};