Instantly share code, notes, and snippets.

Created September 11, 2011 02:48
Show Gist options
• Save tsaniel/1209102 to your computer and use it in GitHub Desktop.
The eight queens puzzle - get the number of soultions of an n queens puzzle
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
 function ( a, // bitmask that all queens are placed b // placeholder for result ) { return function f( c, // row d, // left diagnal e, // right diagnal g, // placeholder for places where queens can be placed in h // placeholder for the position where the queen is placed in ) { for (g = a ^ c && a & ~(c | d | e); h = -g & g; g-=h) // loop through all subtrees f(c + h, d + h << 1, e + h >> 1); // to the next depth a^c||++b; // add one solution }(b = 0, 0, 0), b; }
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
 function(a,b){return function f(c,d,e,g,h){for(g=a^c&&a&~(c|d|e);h=-g&g;g-=h)f(c+h,d+h<<1,e+h>>1);a^c||++b}(b=0,0,0),b}
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
 DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE Version 2, December 2004 Copyright (C) 2011 YOUR_NAME_HERE Everyone is permitted to copy and distribute verbatim or modified copies of this license document, and changing it is allowed as long as the name is changed. DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. You just DO WHAT THE FUCK YOU WANT TO.
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
 { "name": "nQueen", "description": "Get the number of soultions of an n queens puzzle.", "keywords": [ "eight queens", "queens", "eight queens puzzle", "puzzle" ] }
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
 Foo
Expected value: 92
Actual value:
to join this conversation on GitHub. Already have an account? Sign in to comment