Skip to content

Instantly share code, notes, and snippets.

@michaelfeathers
Created June 28, 2014 23:25
Show Gist options
  • Save michaelfeathers/2cf9e1599e06d0563f2e to your computer and use it in GitHub Desktop.
Save michaelfeathers/2cf9e1599e06d0563f2e to your computer and use it in GitHub Desktop.

Revisions

  1. michaelfeathers created this gist Jun 28, 2014.
    17 changes: 17 additions & 0 deletions markvchaney.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,17 @@
    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