Created
January 14, 2015 14:53
-
-
Save keyvanakbary/e58efdd7fbb77dbe78f4 to your computer and use it in GitHub Desktop.
Evaluate e^x https://www.hackerrank.com/challenges/eval-ex
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (defn factorial [n] | |
| (if (pos? n) (* n (factorial (dec n))) 1)) | |
| (defn calculate-e [x precision] | |
| (if (pos? precision) | |
| (+ (/ (Math/pow x precision) (factorial precision)) | |
| (calculate-e x (dec precision))) | |
| 1)) | |
| (dotimes [n (Integer/parseInt (read-line))] | |
| (println (calculate-e (Float/parseFloat (read-line)) 9))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment