-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds the solution of exercise 2.40(uniqure-pairs)
- Loading branch information
Showing
1 changed file
with
16 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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))))) |