そのままコードにする
気づいたこと
「そのままコードにすること」
;;;q.1.33 (define (filtered-accumlate-r filter combiner null-value term a next b) (if (filter a b) null-value (combiner (term a) (filtered-accumlate-r filter combiner null-value term (next a) next b) ) ) ) (define (accumlate_filter-r combiner null-value term a next b) (filtered-accumlate-r (lambda (x y) (> x y) ) combiner null-value term a next b) ) (define (sum_acu_filter_r term a next b) (accumlate_filter-r + 0 term a next b) ) (sum_acu_filter_r (lambda (x) x) 0 (lambda (y) (+ y 1)) 10 ) ;;;q.1.33.b (define (gcd a b) (if (= b 0) a (gcd b (modulo a b))) ) (gcd 206 40) (gcd 20 40) (define (gcdValueIsOne? a b) (if (= (gcd a b) 1) #t #f ) ) (gcdValueIsOne? 4 8) (define (next-gcd-is-One n targ) (define (iter x) (if (gcdValueIsOne? x targ) x (iter (+ x 1)) ) ) (iter (+ n 1)) ) ((lambda (x) (next-gcd-is-One x 37) ) 3 ) (next-gcd-is-One 1 10) ;3 (next-gcd-is-One 3 10) ;7 (next-gcd-is-One 7 10) ;9 (next-gcd-is-One 9 10) (* 3 7 9) (define (q.1.33.b n) (filtered-accumlate-r (lambda (h i) (> h i) ) * 1 (lambda (z) z) 1 (lambda (x) (next-gcd-is-One x n) ) n ) ) (q.1.33.b 10)
schemeたのし