-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprimit.scm
62 lines (52 loc) · 1.17 KB
/
primit.scm
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
(define (id x) x)
(define (map op xs)
(foldr (lambda (a b)
(cons (op a) b))
'()
xs))
(define (append l1 l2)
(foldr (lambda (a b)
(cons a b))
l2
l1))
(define (flatmap f xs1)
(foldr (lambda (a b)
(append (f a) b))
'()
xs1))
(define (filter p xs)
(foldr (lambda (a b)
(if (p a)
(cons a b)
b))
xs))
(define (length xs)
(foldr (lambda (a b)
(+ b 1))
0
xs))
(define test
(lambda (n xs gap)
(if (null? xs)
#t
(and (not (= n (car xs)))
(not (= n (+ (car xs) gap)))
(not (= n (- (car xs) gap)))
(test n (cdr xs) (+ gap 1))))))
(define test0
(lambda (x xs)
(test x xs 1)))
(define r8 (range 1 8))
(define (queens pre)
(flatmap (lambda (x1)
(flatmap (lambda (xs)
(if (test0 x1 xs)
(cons (cons x1 xs) '())
'()))
pre))
r8))
(define q8
(foldr (lambda (a b)
(queens b))
'(())
r8))