-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpractice4.41.scm
More file actions
58 lines (53 loc) · 1.22 KB
/
practice4.41.scm
File metadata and controls
58 lines (53 loc) · 1.22 KB
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
(define (all-different l)
(define (different first rest)
(if (null? rest)
#t
(if (= first (car rest))
#f
(different first (cdr rest)))))
(if (null? l)
#t
(if (different (car l) (cdr l))
(all-different (cdr l))
#f)))
(define (extend-list l)
(define (not-appear num)
(define (loop num l)
(if (null? l)
#t
(if (= num (car l))
#f
(loop num (cdr l)))))
(loop num l))
(let ((numbers '(1 2 3 4 5)))
(let ((valid-numbers
(filter
not-appear
numbers)))
(map (lambda (x)
(append l (list x)))
valid-numbers))))
(define (accumulate op proc x)
(if (null? x)
'()
(op (proc (car x))
(accumulate op proc (cdr x)))))
(define (flatmap proc x)
(accumulate append proc x))
(define (solve)
(define (r-all x)
(and (not (= (car x) 5))
(not (= (cadr x) 1))
(not (or (= (caddr x) 1) (= (caddr x) 5)))
(= (- (cadddr x) (caddr x)) 1)
(not (= (abs (- (car (cddddr x)) (caddr x))) 1))
(not (= (abs (- (caddr x) (cadr x))) 1))))
(filter
r-all
(filter
all-different
(flatmap extend-list
(flatmap extend-list
(flatmap extend-list
(flatmap extend-list
'((1) (2) (3) (4) (5)))))))))