blob: 702e5cdc2810921738b97d8b9082ef4c1ca52d24 (
plain)
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
|
#lang racket
(require "../../shared/chapter1.rkt")
(require sicp)
;; sum of squares of the prime numbers in the interval a to b
(define (prime? x)
(all-miller-raban x))
(define (square-prime-sum a b)
(filtered-accumulate
prime?
(lambda (x y) (+ x y))
0
(lambda (x) (* x x))
a inc b))
(square-prime-sum 2 5)
(define (coprime-product n)
(filtered-accumulate
(coprimer n)
(lambda (x y) (* x y))
1
(lambda (x) x)
1 inc (- n 1)))
(coprime-product 10)
|