Created
October 13, 2015 20:03
-
-
Save tsaiDavid/82df01e740860cbb5796 to your computer and use it in GitHub Desktop.
nQueens Solution written with bitwise operators
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
function N(n) { | |
function Hack(R, e, a, c, t, o, r) { | |
for (t = ~ (R | e | a) & c; t > 0;) | |
t ^= o = t & -t, r += Hack(R | o, (e | o) >> 1, (a | o) << 1, c, 0, 0, 0); | |
return R == c && r++, r | |
} | |
return Hack(0, 0, 0, (1 << n) - 1, 0, 0, 0) | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment