queenst =: (, #: I.@,@(</)&i.)~ (] #"1~ [ */@:~:&(|@-/) {)&.|: ! A.&i. ]
This is the calculation, and you can output all 92 solutions for the 8 queens problems like this: queenst 8
0 4 7 5 2 6 1 3
0 5 7 2 6 3 1 4
0 6 3 5 7 1 4 2
....
each column is a row number, and the integer is which column the queen is in, or vice versa on rows and columns.,or print how many solutions
$queens
92 8
$ gives the 'shape' of the array, that is 92 rows (solutions) x 8 columns (8-queens problem).I always return to J, because I enjoy mathematics and functional programming. Like math, you work with symbols you learn to think as you code in an interpreted window, somewhat like when working in the Lisp REPL. Ken Iverson created the APL language in 1960, and won an ACM Turing Award and gave a lecture 'Notation as a Tool of Thought', which sums it up better than I could ever hope to express it [3].
J was a collaboration between him, Arthur Whitney (of finance's k language, and kdb fame), and Roger Hui, in an attempt to improve on APL, and to do away with needing a special character keyboard. It is under the GPL3 license today. J uses the ASCII character set, and is very functional and composable.
[1] http://code.jsoftware.com/wiki/Essays/N_Queens_Problem
[2] http://code.jsoftware.com/wiki/Essays/Queens_and_Knights
[3] http://www.jsoftware.com/papers/tot.htm