Created
July 17, 2015 03:16
-
-
Save cametan001/f97150c5bae8ccf7cae9 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 (estimate-pi trials) | |
(sqrt (/ 6 (monte-carlo trials cesaro-test)))) | |
(define (cesaro-test) | |
(= (gcd (rand) (rand)) 1)) | |
(define (monte-carlo trials experiment) | |
(define (iter trials-remaining trials-passed) | |
(cond ((= trials-remaining 0) | |
(/ trials-passed trials)) | |
((experiment) | |
(iter (- trials-remaining 1) (+ trials-passed 1))) | |
(else | |
(iter (- trials-remaining 1) trials-passed)))) | |
(iter trials 0)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment