Created
February 10, 2012 19:03
-
-
Save albertein/1791782 to your computer and use it in GitHub Desktop.
Third challenge for http://apply.embed.ly
This file contains 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
def count_words(max_occurrences, unique_words) | |
unique_words -= 1 | |
total_words = max_occurrences | |
for i in 2..unique_words | |
total_words += max_occurrences / i.to_f | |
end | |
return total_words | |
end | |
def search(max_ocurrences, unique_words) | |
half_words = count_words(max_ocurrences, unique_words) / 2 | |
total = max_ocurrences | |
for i in 2..unique_words | |
total += max_ocurrences / i.to_f | |
if total > half_words | |
return i | |
end | |
end | |
end | |
puts search 3520, 900 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment