Skip to content

Commit

Permalink
Adds the solution of exercise 2.40(uniqure-pairs)
Browse files Browse the repository at this point in the history
  • Loading branch information
veselinn committed Apr 16, 2012
1 parent d1bbd39 commit 0a0ebcf
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions chapter2/40.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
; Exercise 2.40:
; Define a procedure unique-pairs that, given an in-
; teger n , generates the sequence of pairs (i , j ) with 1 ≤ j < i ≤ n .
; Use unique-pairs to simplify the definition of prime-sum-pairs
; given above.

(define (enumerate-interval low high)
(if (> low high)
null
(cons low (enumerate-interval (+ low 1) high))))

(define (unique-pairs low high)
(if (>= low high)
null
(append (map (lambda (x) (cons high x)) (enumerate-interval low (- high 1)))
(unique-pairs low (- high 1)))))

0 comments on commit 0a0ebcf

Please sign in to comment.