-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added queens choice, just need to get the svg to change
- Loading branch information
t03jam8
committed
Dec 24, 2017
1 parent
702a259
commit 571c717
Showing
8 changed files
with
131 additions
and
38 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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,52 @@ | ||
exports.calcQueens = n => { | ||
let queens = 0; | ||
let j = 0; | ||
let solutions = 0; | ||
let col = Array(n).fill(0); | ||
let aL = Array(n).fill(0); | ||
let aR = Array(n).fill(0); | ||
const individualRes = [1, 2, 3, 4]; | ||
const allRes = []; | ||
|
||
function recur() { | ||
for (let i = 0; i < n; i++) { | ||
var paL = aL.slice(); // hiostory | ||
var paR = aR.slice(); // hoistory, needs nerw reference | ||
if (col[i] === 0 && aL[i] === 0 && aR[i] === 0) { | ||
col[i] = 1; | ||
individualRes[j] = i; | ||
// the prevous ones | ||
// take the next linearaL.push(0) | ||
aL.push(0); | ||
aL.shift(); | ||
aR.unshift(0); | ||
aR.pop(); | ||
// adding the new diag avoid | ||
if (aL[i - 1] === 0) aL[i - 1] = 1; | ||
if (aR[i + 1] === 0) aR[i + 1] = 1; | ||
queens++; | ||
/// are there any spaces | ||
let test = []; | ||
aL.forEach((el, i) => (test[i] = aL[i] | aR[i] | col[i])); | ||
if (queens === n) { | ||
allRes.push(individualRes.concat()); | ||
solutions++; | ||
} | ||
j++; | ||
if (!(test.join("") === "1".repeat(n))) recur(); | ||
j--; | ||
col[i] = 0; | ||
aL = paL; | ||
aR = paR; | ||
queens--; | ||
} | ||
} | ||
} | ||
recur(); | ||
// console.log('Solution: ', solutions) | ||
return allRes; | ||
}; | ||
|
||
// console.log(calc(4)); | ||
|
||
// module.exports = calc; |
This file contains 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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
exports.calc = n => { | ||
exports.calcRooks = n => { | ||
let rooks = 0; | ||
let j = 0; | ||
let solutions = 0; | ||
|
This file contains 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
This file contains 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
This file contains 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 |
---|---|---|
@@ -1,5 +1 @@ | ||
body { | ||
margin: 0; | ||
padding: 0; | ||
font-family: sans-serif; | ||
} | ||
|
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.