mirror of
https://github.com/justinethier/cyclone.git
synced 2025-07-11 14:57:36 +02:00
Initial file
This commit is contained in:
parent
bc26daa71f
commit
b561bcd09a
2 changed files with 1515 additions and 0 deletions
1480
debug/compilation/nqueens.c
Normal file
1480
debug/compilation/nqueens.c
Normal file
File diff suppressed because one or more lines are too long
35
debug/compilation/nqueens.scm
Normal file
35
debug/compilation/nqueens.scm
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
;(cond-expand
|
||||||
|
; (cyclone
|
||||||
|
(import
|
||||||
|
(scheme base)
|
||||||
|
(scheme write))
|
||||||
|
; )
|
||||||
|
; (else #f))
|
||||||
|
|
||||||
|
(define (nqueens n)
|
||||||
|
|
||||||
|
(define (dec-to n)
|
||||||
|
(let loop ((i n) (l '()))
|
||||||
|
(if (= i 0) l (loop (- i 1) (cons i l)))))
|
||||||
|
|
||||||
|
(define (try x y z)
|
||||||
|
(if (null? x)
|
||||||
|
(if (null? y)
|
||||||
|
1
|
||||||
|
0)
|
||||||
|
(+ (if (ok? (car x) 1 z)
|
||||||
|
(try (append (cdr x) y) '() (cons (car x) z))
|
||||||
|
0)
|
||||||
|
(try (cdr x) (cons (car x) y) z))))
|
||||||
|
|
||||||
|
(define (ok? row dist placed)
|
||||||
|
(if (null? placed)
|
||||||
|
#t
|
||||||
|
(and (not (= (car placed) (+ row dist)))
|
||||||
|
(not (= (car placed) (- row dist)))
|
||||||
|
(ok? row (+ dist 1) (cdr placed)))))
|
||||||
|
|
||||||
|
(try (dec-to n) '() '()))
|
||||||
|
|
||||||
|
(write
|
||||||
|
(nqueens 8))
|
Loading…
Add table
Reference in a new issue