Skip to content

Instantly share code, notes, and snippets.

@rohit89
Created February 11, 2012 12:25
Show Gist options
  • Save rohit89/1799191 to your computer and use it in GitHub Desktop.
Save rohit89/1799191 to your computer and use it in GitHub Desktop.
Embedly Challenge #3
def harmonic_sum n
(1..n).each.inject(0) {|sum, i| sum += (1.0 / i)}
end
total_words = 2520 * harmonic_sum(900)
half = total_words / 2
sum = 0
(1..900).each do |i|
sum += 1.0 / i
if sum * 2520 >= half
puts i
break
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment