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))))
- (defn calculate-pi [throws]
- (loop [hits 0
- throws-left throws] ; initial number of throws
- (zero? throws-left) (* 4.0 (/ hits throws)); all thrown, return value
- (<= (r-squared (rand) (rand)) 0.25) (recur (inc hits) (dec throws-left))
- (> (r-squared (rand) (rand)) 0.25) (recur hits (dec throws-left))
- )
- )
- java.lang.UnsupportedOperationException: Can only recur from tail position (Assi
- gnment1.clj:20)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement