Advertisement
Guest User

Untitled

a guest
Sep 19th, 2010
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scheme 0.47 KB | None | 0 0
  1. (defn r-squared [x y]
  2.   (+ (* (- 0.5 x) (- 0.5 x))
  3.      (* (- 0.5 y) (- 0.5 y))))
  4.  
  5. This may not be right, but it's closer to what you probably meant.
  6.  
  7. (defn calculate-pi [throws]
  8.   (loop [hits 0
  9.          throws-left throws]            ; initial number of throws
  10.     (cond
  11.      (zero? throws-left) (* 4.0 (/ hits throws)) ; all thrown, return value
  12.      (<= (r-squared (rand) (rand)) 0.25) (recur (inc hits) (dec throws-left))
  13.      :else (recur hits (dec throws-left))))))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement