Skip to content

Instantly share code, notes, and snippets.

@rpdillon
Last active December 20, 2015 22:39
Show Gist options
  • Save rpdillon/6206308 to your computer and use it in GitHub Desktop.
Save rpdillon/6206308 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
words = {}.tap{|h| h.default = 0}
corpus = %x[ls].split.select{|n| n =~ /\.txt/}
.map{|f| File.read(f)}.reduce(&:+).split
.map{|w| w.downcase.gsub(/[^a-z]/,'')}
corpus.each{|w| words[w] += 1}
ranked_words = words.select{|k,_| k.length > 3}.sort_by{|_,v| -v}[0..5000]
10.times do
puts ranked_words.sample(4).map(&:first).map(&:capitalize).join
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment