Skip to content

Instantly share code, notes, and snippets.

@tsaiDavid
Created October 13, 2015 20:03
Show Gist options
  • Save tsaiDavid/82df01e740860cbb5796 to your computer and use it in GitHub Desktop.
Save tsaiDavid/82df01e740860cbb5796 to your computer and use it in GitHub Desktop.
nQueens Solution written with bitwise operators
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