Created
October 12, 2014 19:18
-
-
Save akulakov/9e9d18eeb8db6dc23281 to your computer and use it in GitHub Desktop.
Bitfunc: recursive, iterative, compare
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
(define (bitfunc-recur steps x1 x2) | |
(define (step) (/ (- x2 x1) steps)) | |
(if (> steps 0) | |
(+ (bitfunc-rect x1 (+ x1 (step))) (bitfunc-recur (- steps 1) (+ (step) x1) x2)) | |
0)) | |
(define (d x) (exact->inexact x)) | |
(define (bitfunc-iter steps x1 x2) | |
(define step 0) | |
(set! step (/ (- x2 x1) steps)) | |
(define area 0) | |
(do ((n 0 (+ n 1))) ((>= n steps)) | |
(set! area (+ area (bitfunc-rect x1 (+ x1 step)))) | |
(set! x1 (+ x1 step)) | |
) | |
(exact->inexact area)) | |
(define (compare steps x1 x2) | |
(abs (- (bitfunc-recur steps x1 x2) (bitfunc-iter steps x1 x2))) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment