Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (defn sq[n]
- (loop [candidate (/ n 2.0)
- prev-candidate (double n)]
- (let [step (/ (abs (- prev-candidate candidate)) 2)
- square (* candidate candidate)
- epsilon (abs (- n square))]
- (if (< epsilon 0.001) (round candidate)
- (if (> square n) (recur (- candidate step) candidate) (recur (+ candidate step) candidate))))))
- (fact (sq 4) => 2)
- (fact (sq 16) => 4)
- (fact (sq 9) => 3)
- (fact (sq 49) => 7)
Add Comment
Please, Sign In to add comment