/usr/share/zenlisp/queens.l is in zenlisp 2013.11.22-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 | ; zenlisp example program
; By Nils M Holm, 1998-2008
; See the file LICENSE for conditions of use.
; Solve the N-queens problem.
; (queens '#4)
; (queens '#5 '#2) ; print only two solutions
(require '~nmath)
(define (queens board-size . limit)
(letrec
((column
(lambda (x)
(quotient x board-size)))
(row
(lambda (x)
(remainder x board-size)))
(incr
(lambda (x)
(+ '#1 x)))
(decr
(lambda (x)
(- x '#1)))
(can-attack-straight-p
(lambda (x y)
(or (= (row x) (row y))
(= (column x) (column y)))))
(abs-diff
(lambda (x y)
(cond ((< x y) (- y x))
(t (- x y)))))
(can-attack-diagonal-p
(lambda (x y)
(= (abs-diff (column x) (column y))
(abs-diff (row x) (row y)))))
(can-attack-p
(lambda (x y)
(or (can-attack-straight-p x y)
(can-attack-diagonal-p x y))))
(safe-place-p
(lambda (x b)
(cond ((null b) :t)
((can-attack-p (car b) x) :f)
(t (safe-place-p x (cdr b))))))
(next-column
(lambda (q)
(* (quotient (+ q board-size) board-size)
board-size)))
(solve
(lambda (q c b r k)
(cond ((equal c board-size)
(cond ((or (null limit)
(< k (car limit)))
(solve (incr (car b))
(decr c)
(cdr b)
(cons b r)
(+ '#1 k)))
(t r)))
((> (column q) c)
(cond ((null b) r)
(t (solve (incr (car b))
(decr c)
(cdr b)
r
k))))
((safe-place-p q b)
(solve (next-column q)
(incr c)
(cons q b)
r
k))
(t (solve (incr q) c b r k))))))
(map (lambda (b*)
(map (lambda (x)
(remainder x board-size))
b*))
(reverse (solve '#0 '#0 () () '#0)))))
|