-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexercise2-41.lisp
More file actions
25 lines (22 loc) · 837 Bytes
/
exercise2-41.lisp
File metadata and controls
25 lines (22 loc) · 837 Bytes
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
(define (enumerate-interval low high)
(if (> low high)
'()
(cons low (enumerate-interval (+ low 1) high))))
(define (flatmap proc seq)
(foldr append '() (map proc seq)))
;(define (unique-pairs n)
; (flatmap (lambda (i)
; (map (lambda (j) (list j i))
; (enumerate-interval 1 (- i 1))))
; (enumerate-interval 2 n)))
(define (sum-ordered-triples n s)
(filter (lambda (triple) (= s (foldr + 0 triple)))
(flatmap (lambda (i)
(flatmap (lambda (j)
(map (lambda (k) (list i j k))
(enumerate-interval 1 n))
)
(enumerate-interval 1 n)))
(enumerate-interval 1 n))))
(display (sum-ordered-triples 10 5))
(newline)