Sha256: d210dea6a7d9bda94d60eda1695b5430d0c3da714ddbaa08c84d44a5dd5fa741

Contents?: true

Size: 1.31 KB

Versions: 13

Compression:

Stored size: 1.31 KB

Contents

(define n-queens
  {number --> symbol}
  N -> (do (map (/. X (output "~A~%" X)) (n-queens-loop N (initialise N))) ok))

(define initialise
   {number --> (list number)}
   0 -> []
   N -> [1 | (initialise (- N 1))])
 
(define n-queens-loop
  {number --> (list number) --> [(list number)]}
  N Config -> []    where (all_Ns? N Config)
  N Config -> [Config | (n-queens-loop N (next_n N Config))] 
                                       where (and (ok_row? Config) (ok_diag? Config))
  N Config -> (n-queens-loop N (next_n N Config)))
 
(define all_Ns?
  {number --> (list number) --> boolean}
   _ [] -> true
  N [N | Ns] -> (all_Ns? N Ns)
  _ _ -> false)
 
(define next_n
  {number --> (list number) --> (list number)}
  N [N | Ns] -> [1 | (next_n N Ns)]
  _ [N | Ns] -> [(+ 1 N) | Ns])
 
(define ok_row?
  {(list number) --> boolean}
  [] -> true
  [N | Ns] -> false     where (element? N Ns)
  [_ | Ns] -> (ok_row? Ns))
 
(define ok_diag?
  {(list number) --> boolean} 
  [] -> true
  [N | Ns] -> (and (ok_diag_N? (+ N 1) (- N 1) Ns) 
                                (ok_diag? Ns)))
 
(define ok_diag_N?
  {number --> number --> (list number) --> boolean}
  _ _ [] -> true
  Up Down [Up | _] -> false
  Up Down [Down | _] -> false
  Up Down [_ | Ns] -> (ok_diag_N? (+ 1 Up) (- Down 1) Ns)) 

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
shen-ruby-0.10.0 shen/release/benchmarks/N_queens.shen
shen-ruby-0.9.0 shen/release/benchmarks/N_queens.shen
shen-ruby-0.8.1 shen/release/benchmarks/N_queens.shen
shen-ruby-0.8.0 shen/release/benchmarks/N_queens.shen
shen-ruby-0.7.0 shen/release/benchmarks/N_queens.shen
shen-ruby-0.6.0 shen/release/benchmarks/N_queens.shen
shen-ruby-0.5.0 shen/release/benchmarks/N_queens.shen
shen-ruby-0.4.1 shen/release/benchmarks/N_queens.shen
shen-ruby-0.4.0 shen/release/benchmarks/N_queens.shen
shen-ruby-0.3.1 shen/release/benchmarks/N_queens.shen
shen-ruby-0.3.0 shen/release/benchmarks/N_queens.shen
shen-ruby-0.2.0 shen/release/benchmarks/N_queens.shen
shen-ruby-0.1.0 shen/release/benchmarks/N_queens.shen