Skip to content

Instantly share code, notes, and snippets.

@proglottis
Created June 12, 2013 07:14
Show Gist options
  • Save proglottis/5763391 to your computer and use it in GitHub Desktop.
Save proglottis/5763391 to your computer and use it in GitHub Desktop.
Word number
#!/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