- Notifications
You must be signed in to change notification settings - Fork98
Init#1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
Uh oh!
There was an error while loading.Please reload this page.
Merged
Init#1
Changes fromall commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
15 changes: 15 additions & 0 deletions.vscode/launch.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
// Use IntelliSense to learn about possible attributes. | ||
// Hover to view descriptions of existing attributes. | ||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 | ||
"version": "0.2.0", | ||
"configurations": [ | ||
{ | ||
"type": "node", | ||
"request": "launch", | ||
"name": "Launch Program", | ||
"program": "${workspaceFolder}/Main.js", | ||
"console": "integratedTerminal", | ||
} | ||
] | ||
} |
10 changes: 10 additions & 0 deletionsMain.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// Import | ||
var permutationWithoutDuplicates = require("./PermutationsWithoutDuplicates.js"); | ||
var permutationWithDuplicates = require("./PermutationsWithDuplicates.js"); | ||
var subsets = require("./Subsets.js"); | ||
// Invocation | ||
// permutationWithoutDuplicates.main(); | ||
// permutationWithDuplicates.main(); | ||
// subsets.main(); |
36 changes: 36 additions & 0 deletionsPermutationsWithDuplicates.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// https://leetcode.com/problems/permutations-ii/description/ | ||
// Permutations without | ||
var subsetWithoutDuplicates = function(nums) { | ||
if(nums.lenght == 0){ | ||
return; | ||
} | ||
var solution = []; | ||
subsetWithoutDuplicatesAux(nums, [], solution); | ||
console.log(solution); | ||
} | ||
var subsetWithoutDuplicatesAux = function(nums, current, sol) { | ||
if(nums.length == 0){ | ||
sol.push(current); | ||
} | ||
var setNums = new Set(); | ||
nums.forEach((value, index) => { | ||
if(setNums.has(value)) { | ||
return; | ||
} | ||
setNums.add(value); | ||
var newCurrent = [...current, value] | ||
var newNum = nums.filter(function(num, idx) { return index !== idx}); | ||
subsetWithoutDuplicatesAux(newNum, newCurrent, sol); | ||
}) | ||
} | ||
function main() { | ||
subsetWithoutDuplicates([1,1,2,3]); | ||
} | ||
module.exports.main = main; |
30 changes: 30 additions & 0 deletionsPermutationsWithoutDuplicates.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
//https://leetcode.com/problems/permutations/description/ | ||
// Permutations wihto | ||
var subsetWithDuplicates = function(nums) { | ||
if(nums.lenght == 0){ | ||
return; | ||
} | ||
var solution = []; | ||
subsetWithDuplicatesAux(nums, [], solution); | ||
console.log(solution); | ||
} | ||
var subsetWithDuplicatesAux = function(nums, current, sol) { | ||
if(nums.length == 0){ | ||
sol.push(current); | ||
} | ||
for(var i = 0; i < nums.length; i++) { | ||
var newCurrent = [...current, nums[i]] | ||
var newNum = nums.filter(function(num, index) { return index !== i}); | ||
subsetWithDuplicatesAux(newNum, newCurrent, sol); | ||
} | ||
} | ||
function main() { | ||
subsetWithDuplicates([1,2,3]) | ||
} | ||
module.exports.main = main; |
20 changes: 20 additions & 0 deletionsSubsets.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
var subsets = function(nums) { | ||
var ret = []; | ||
subsetByPosition = function (nums, position, current) { | ||
console.log(current); | ||
if(position == nums.length) { | ||
return [current]; | ||
} | ||
var currentRight = current.slice().concat([nums[position]]); | ||
return subsetByPosition(nums, position + 1, currentRight).concat(subsetByPosition(nums, position + 1, current)); | ||
} | ||
return subsetByPosition(nums, 0, []); | ||
}; | ||
function main() { | ||
console.log(subsets([1,2,3])); | ||
} | ||
module.exports.main = main; |
95 changes: 95 additions & 0 deletionsTicTacToe.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
class TicTacToe { | ||
constructor() { | ||
this.matrix = []; | ||
for(var i = 0; i < 3; i++) { | ||
this.matrix[i] = []; | ||
for(var j = 0; j < 3; j++) { | ||
this.matrix[i][j] = "-"; | ||
} | ||
} | ||
}; | ||
validToken(token) { | ||
if (token == "X" || token == "0" || token == "-") { | ||
return true; | ||
} | ||
console.log("Token is invalid"); | ||
return false; | ||
} | ||
addToken(x, y, token) { | ||
// Check valid positions | ||
if(this.validToken(token)) { | ||
this.matrix[x][y] = token; | ||
} | ||
}; | ||
printBoard() { | ||
for(var row = 0; row < 3; row ++) { | ||
console.log(this.matrix[row][0] + "|" | ||
+ this.matrix[row][1] + "|" | ||
+ this.matrix[row][2]); // Check new line; | ||
} | ||
} | ||
isBoardFull() { | ||
for(var row = 0; row < 3; row ++) { | ||
for(var col = 0; col < 3; col ++) { | ||
if(this.matrix[row][col] === "-") { | ||
console.log("Is not full"); | ||
return false; | ||
} | ||
} | ||
} | ||
console.log("Is full"); | ||
return true; | ||
} | ||
makeMove() { | ||
if(this.isBoardFull()) { | ||
throw "Error Board is Full"; | ||
} | ||
for(var row = 0; row < 3; row ++) { | ||
for(var col = 0; col < 3; col ++) { | ||
if(this.matrix[row][col] === "-") { | ||
this.addToken(row, col, "0"); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
ticTacToe = new TicTacToe(); | ||
ticTacToe.isBoardFull(); | ||
ticTacToe.addToken(0,1,"X"); | ||
ticTacToe.printBoard(); | ||
var iter = 0; | ||
while(iter < 8) { | ||
ticTacToe.makeMove(); | ||
iter++; | ||
} | ||
console.log("after 8 moves"); | ||
ticTacToe.isBoardFull(); | ||
ticTacToe.printBoard(); | ||
ticTacToe.makeMove(); | ||
// ticTacToe.printBoard(); | ||
// ticTacToe.addToken(0,0,"X"); | ||
// ticTacToe.printBoard(); | ||
// // var readline = require('readline') | ||
// // const rl = readline.createInterface({ | ||
// // input: process.stdin, | ||
// // output: process.stdout | ||
// // }); | ||
// // var response = rl.question('Whats your name : ', answer) | ||
// // function answer(response) { | ||
// // console.log(response) | ||
// // } |
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.