Skip to content

Instantly share code, notes, and snippets.

@uroybd
Last active August 29, 2015 14:23
Show Gist options
  • Save uroybd/c5c980e6de998cb7aa30 to your computer and use it in GitHub Desktop.
Save uroybd/c5c980e6de998cb7aa30 to your computer and use it in GitHub Desktop.
Hackerrank e^x
(loop [test-case-remaining (Integer/parseInt (read-line))]
(while (not= 0 test-case-remaining)
(do (println (let [factorial (fn [n]
(reduce * (take n (range 1 (inc n)))))
to-the-power (fn [n m]
(reduce * (repeat m n)))
e-to-the-power-x (fn [x]
(inc (apply + (map #(float (/ (to-the-power x %)
(factorial %)))
(range 1 10)))))]
(e-to-the-power-x (Float/parseFloat (read-line)))))
(dec test-case-remaining))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment