Skip to content

Instantly share code, notes, and snippets.

@lexun
Last active January 4, 2016 11:19
Show Gist options
  • Save lexun/8614885 to your computer and use it in GitHub Desktop.
Save lexun/8614885 to your computer and use it in GitHub Desktop.
Comparing ruby and clojure solutions - https://www.hackerrank.com/challenges/eval-ex
(dotimes [n (read-string (read-line))]
(let [x (read-string (read-line))]
(println
(format "%.4f"
(float (reduce (fn [m, i] (+ m (/ (reduce * (repeat i x))
(reduce * (range 1 (inc i))))))
(int 1)
(range 1 10)))))))
gets.to_i.times do
gets.to_f.instance_eval do
puts((1..9).inject(1) { |m, i| m + self**i / (1..i).reduce(:*) }.round(4))
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment