Here you go!
C (http://rosettacode.org/wiki/N-queens_problem#C)
Program 1 (compiled with gcc -O3 c1.c -o bin/c1)[0]
real 0m0.003s
user 0m0.000s
sys 0m0.002s
Program 2: (compiled with gcc -O3 c2.c -o bin/c2)[1]
Same as above, second code listing (faster while still readable,excluded unreadable fastest c version)
real 0m0.001s
user 0m0.000s
sys 0m0.001s
Haskell (
http://rosettacode.org/wiki/N-queens_problem#Haskell)
Program 1 (modified to do 8 queens like the c versions, compiled with: ghc -O2 -threaded haskell2.hs -o bin/haskell2)[2]
real 0m0.010s
user 0m0.005s
sys 0m0.005s
Program 2 (modified to do 8 queens like the c version, compiled with: ghc -O2 -threaded haskell2.hs -o bin/haskell2)[3] (word of warning, this program is only 52% efficient according to ghc and has a lot of optimization that could be done)
real 0m0.006s
user 0m0.006s
sys 0m0.000s
Note that the fastest Haskell solution was also the shortest by quite a bit. Are you convinced yet?
EDIT: Found an ATS solution, but I'm not setup to compile it: http://www.ats-lang.org/SERVER/MYCODE/Patsoptaas_serve.php?m...
0: C, solution 1
#include
#include
int count = 0;
void solve(int n, int col, int *hist)
{
if (col == n) {
printf("\nNo. %d\n-----\n", ++count);
for (int i = 0; i
1: c solution 2
#include
#include
#include
typedef uint32_t uint;
uint full, *qs, count = 0, nn;
void solve(uint d, uint c, uint l, uint r)
{
uint b, a, *s;
if (!d) {
count++;
#if 0
printf("\nNo. %d\n===========\n", count);
for (a = 0; a >= 1)) & full;
if (a != full)
for (*(s = qs + --d) = 0, b = 1; b
2: Haskell solution 1 (comments stripped out for comparison)
import Control.Monad
import Data.List
queens :: Int -> [[Int]]
queens n = map fst $ foldM oneMoreQueen ([],[1..n]) [1..n] where
oneMoreQueen (y,d) _ = [(x:y, delete x d) | x putStrLn [if z == x then 'Q' else '.' | z
3: Haskell solution 2
import Control.Monad (foldM)
import Data.List ((\\))
main :: IO ()
main = mapM_ print $ queens 8
queens :: Int -> [[Int]]
queens n = foldM f [] [1..n]
where
f qs _ = [q:qs | q