Skip to content

Instantly share code, notes, and snippets.

@albertein
Created February 10, 2012 19:03
Show Gist options
  • Save albertein/1791782 to your computer and use it in GitHub Desktop.
Save albertein/1791782 to your computer and use it in GitHub Desktop.
Third challenge for http://apply.embed.ly
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