Skip to content

Instantly share code, notes, and snippets.

@pirate
Forked from michaelfeathers/markvchaney.rb
Created May 2, 2016 07:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pirate/378ca8835f463119f89c5178b223338f to your computer and use it in GitHub Desktop.
Save pirate/378ca8835f463119f89c5178b223338f to your computer and use it in GitHub Desktop.
stems = ARGF.read
.split
.each_cons(2)
.group_by { |word_pair| word_pair[0] }
def next_word ary
ary[rand(ary.length).to_i][1]
end
e = Enumerator.new do |e|
word = stems.first.first
while word
e << word
word = next_word(stems[word] || stems.first)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment