Created
June 12, 2013 07:14
-
-
Save proglottis/5763391 to your computer and use it in GitHub Desktop.
Word number
This file contains hidden or 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
#!/usr/bin/env ruby | |
def word_number(n, words, separator='-', seed=nil) | |
r, n = n.divmod(words.length) | |
word = [words[n], seed].compact.join(separator) | |
if r < 1 | |
word | |
else | |
word_number(r, words, separator, word) | |
end | |
end | |
words = IO.readlines("/usr/share/dict/words").map(&:strip) | |
ARGF.each_line do |line| | |
puts word_number(line.to_i, words) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment