Skip to content

Instantly share code, notes, and snippets.

@topher6345
Created March 20, 2016 21:11
Show Gist options
  • Save topher6345/27ac4b749863abc2dc2e to your computer and use it in GitHub Desktop.
Save topher6345/27ac4b749863abc2dc2e to your computer and use it in GitHub Desktop.
# == YADTQMCG
## Yet another Donald Trump Quote Markov Chain Generator
# Markov algorithm forked from
# https://gist.github.com/michaelfeathers/2cf9e1599e06d0563f2e
file = ARGF.read.split
pseudo_stems = file.each_cons(4).to_a.shuffle
pseudo_stems << file.each_cons(3).to_a.shuffle
pseudo_stems << file.each_cons(5).to_a.shuffle
pseudo_stems << file.each_cons(6).to_a.shuffle
stems = pseudo_stems.shuffle.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
output = ""
400.times do
output << e.next + " " rescue e.rewind
end
p output
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment