! Copyright (c) 2012 Anonymous
! See http://factorcode.org/license.txt for BSD license.
-USING: kernel sequences math math.combinatorics formatting io locals ;
+USING: kernel sequences math math.combinatorics formatting io ;
IN: rosetta-code.n-queens
! http://rosettacode.org/wiki/N-queens_problem
:: safe? ( board q -- ? )
[let q board nth :> x
- q iota [
+ q <iota> [
x swap
[ board nth ] keep
q swap -
] ;
: solution? ( board -- ? )
- dup length iota [ dupd safe? ] all? nip ;
+ dup length <iota> [ dupd safe? ] all? nip ;
: queens ( n -- l )
- iota all-permutations [ solution? ] filter ;
+ <iota> all-permutations [ solution? ] filter ;
: queens. ( n -- )
queens [ [ 1 + "%d " printf ] each nl ] each ;