Skip to content

Commit a0bbc06

Browse files
Move problems to a folder and beautify main class
1 parent 7528ae0 commit a0bbc06

12 files changed

+79
-50
lines changed

.vscode/settings.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"editor.tabSize": 4,
3+
"[javascript]": {
4+
"editor.tabSize": 2
5+
},
6+
"[json]": {
7+
"editor.tabSize": 2
8+
}
9+
}

CoinChange.js renamed to LeetcodeProblems/CoinChange.js

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -134,21 +134,21 @@ var min = function(a, b, c) {
134134

135135

136136
function main() {
137-
console.log("-------------");
138-
console.log("Approach 1")
139-
console.log(coinChange1([], 3));
140-
console.log(coinChange1([2], 3));
141-
console.log(coinChange1([1, 2, 5], 11));
142-
console.log(coinChange1([3,7,405,436], 8839));
143-
// console.log(coinChange1([370,417,408,156,143,434,168,83,177,280,117], 9953)); takes forever
144-
145-
console.log("-------------");
146-
console.log("Approach 2")
147-
console.log(coinChange2([], 3));
148-
console.log(coinChange2([2], 3));
149-
console.log(coinChange2([1, 2, 5], 11));
150-
console.log(coinChange2([3,7,405,436], 8839));
151-
console.log(coinChange2([370,417,408,156,143,434,168,83,177,280,117], 9953));
137+
// console.log("-------------");
138+
// console.log("Approach 1")
139+
// console.log(coinChange1([], 3));
140+
// console.log(coinChange1([2], 3));
141+
// console.log(coinChange1([1, 2, 5], 11));
142+
// console.log(coinChange1([3,7,405,436], 8839));
143+
// // console.log(coinChange1([370,417,408,156,143,434,168,83,177,280,117], 9953)); takes forever
144+
145+
// console.log("-------------");
146+
// console.log("Approach 2")
147+
// console.log(coinChange2([], 3));
148+
// console.log(coinChange2([2], 3));
149+
// console.log(coinChange2([1, 2, 5], 11));
150+
// console.log(coinChange2([3,7,405,436], 8839));
151+
// console.log(coinChange2([370,417,408,156,143,434,168,83,177,280,117], 9953));
152152

153153
console.log("-------------");
154154
console.log("Approach 3")
@@ -158,4 +158,5 @@ function main() {
158158
console.log(coinChange3([3,7,405,436], 8839));
159159
console.log(coinChange3([370,417,408,156,143,434,168,83,177,280,117], 9953));
160160
}
161-
main();
161+
162+
module.exports.main = main;
File renamed without changes.

GenerateParentheses.js renamed to LeetcodeProblems/GenerateParentheses.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,5 +92,5 @@ function main() {
9292
console.log(`${elem}: ${generateParenthesesApproach2(elem)}`);
9393
})
9494
}
95-
main();
95+
9696
module.exports.main = main
File renamed without changes.

NQueens.js renamed to LeetcodeProblems/NQueens.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,4 +89,5 @@ var main = function(n) {
8989
printMatrixes(solveNQueens(5), 5);
9090
printMatrixes(solveNQueens(6), 6);
9191
}
92-
main();
92+
93+
module.exports.main = main;
File renamed without changes.

TicTacToe.js renamed to LeetcodeProblems/TicTacToe.js

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -60,20 +60,26 @@ class TicTacToe {
6060
}
6161
}
6262

63-
ticTacToe = new TicTacToe();
64-
ticTacToe.isBoardFull();
65-
ticTacToe.addToken(0,1,"X");
66-
ticTacToe.printBoard();
67-
var iter = 0;
68-
while(iter < 8) {
69-
ticTacToe.makeMove();
70-
iter++;
63+
var main = function() {
64+
console.log("TBD");
7165
}
7266

73-
console.log("after 8 moves");
74-
ticTacToe.isBoardFull();
75-
ticTacToe.printBoard();
76-
ticTacToe.makeMove();
67+
module.exports.main = main;
68+
69+
ticTacToe = new TicTacToe();
70+
// ticTacToe.isBoardFull();
71+
// ticTacToe.addToken(0,1,"X");
72+
// ticTacToe.printBoard();
73+
// var iter = 0;
74+
// while(iter < 8) {
75+
// ticTacToe.makeMove();
76+
// iter++;
77+
// }
78+
79+
// console.log("after 8 moves");
80+
// ticTacToe.isBoardFull();
81+
// ticTacToe.printBoard();
82+
// ticTacToe.makeMove();
7783

7884
// ticTacToe.printBoard();
7985
// ticTacToe.addToken(0,0,"X");
File renamed without changes.

Main.js

Lines changed: 32 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,34 @@
1-
// Import
2-
var permutationWithoutDuplicates = require("./PermutationsWithoutDuplicates.js");
3-
var permutationWithDuplicates = require("./PermutationsWithDuplicates.js");
4-
var subsets = require("./Subsets.js");
5-
var generateParentheses = require("./GenerateParentheses.js")
6-
var maximunSubarray = require("./MaximunSubarray.js");
7-
var coinChange = require("./CoinChange.js");
8-
var nQueens = require("./NQueens.js");
9-
var uniquePaths = require("./UniquePaths.js");
10-
var floodFill = require("./FloodFill.js")
1+
const fs = require('fs');
112

12-
// Invocation
3+
const PROBLEMS_FOLDER = './LeetcodeProblems/';
4+
const REGEX_PATTERN_HIDDEN_FILES = /(^|\/)\.[^\/\.]/g;
135

14-
// permutationWithoutDuplicates.main();
15-
// permutationWithDuplicates.main();
16-
// subsets.main();
17-
// generateParentheses.main();
18-
// maximunSubarray.main();
19-
// coinChange.main();
20-
// nQueens.main();
21-
// uniquePaths.main();
22-
// floodFill.main();
6+
var main = async function() {
7+
try {
8+
const problems = await loadProblems();
9+
10+
for(i in problems) {
11+
console.log("Solving: " + problems[i] + ":");
12+
const problem = require(PROBLEMS_FOLDER + problems[i]);
13+
problem.main();
14+
console.log("End of the solution for : " + problems[i] + ",\n\n");
15+
}
16+
} catch (error) {
17+
throw new Error(error);
18+
}
19+
}
20+
21+
var loadProblems = () => {
22+
return new Promise(function (resolve, reject) {
23+
fs.readdir(PROBLEMS_FOLDER, (error, files) => {
24+
if (error) {
25+
reject(error);
26+
} else {
27+
problems = files.filter(item => !(REGEX_PATTERN_HIDDEN_FILES).test(item));
28+
resolve(problems);
29+
}
30+
})
31+
});
32+
}
33+
34+
main();

0 commit comments

Comments
 (0)