Advertisement
Guest User

Untitled

a guest
Sep 19th, 2010
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.51 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.  
  6. (defn calculate-pi [throws]
  7. (loop [hits 0
  8. throws-left throws] ; initial number of throws
  9. (zero? throws-left) (* 4.0 (/ hits throws)); all thrown, return value
  10. (<= (r-squared (rand) (rand)) 0.25) (recur (inc hits) (dec throws-left))
  11. (> (r-squared (rand) (rand)) 0.25) (recur hits (dec throws-left))
  12. )
  13. )
  14.  
  15. java.lang.UnsupportedOperationException: Can only recur from tail position (Assi
  16. gnment1.clj:20)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement