Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (defn r-squared [x y]
- (+ (* (- 0.5 x) (- 0.5 x))
- (* (- 0.5 y) (- 0.5 y))))
- This may not be right, but it's closer to what you probably meant.
- (defn calculate-pi [throws]
- (loop [hits 0
- throws-left throws] ; initial number of throws
- (cond
- (zero? throws-left) (* 4.0 (/ hits throws)) ; all thrown, return value
- (<= (r-squared (rand) (rand)) 0.25) (recur (inc hits) (dec throws-left))
- :else (recur hits (dec throws-left))))))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement