# using a Markov Chain, because this question itself as input text for example

Create a Markov Chain generator, which generates (and outputs) an Order 4 text chain. It must be able to support all plain text formatting used on this question, so be sure to check for punctuation (parentheses count for example, but HTML doesn't need to be accounted for fortunately)! You could even use this question itself as input if you're so inclined. There must be a defined input variable (or something analogous to such, I am aware certain popular esoteric languages do not really have variables per se.)

Your generator also should start sentences with a capital letter, and end with ".", "!", or "?", according to how often those respective characters appear in the input text.

You must also include a way to change the amount of text which should be output, so the only two things that are really configurable are the amount to output and the input string. It should stick with an Order 4 chain, because those happen to be funniest when it all comes down to it really.

Oh and, if your generators happen to create something particularly funny, please feel free to include it in your post for the lulz.

The title of this question was generated using a Markov Chain.

• Can you explain more and give sample I/O? I don't really understand the challenge. – Peter Olson Jul 6 '11 at 18:40
• @Peter Take a look at en.wikipedia.org/wiki/Markov_chain#Markov_text_generators – Cyclone Jul 6 '11 at 19:08
• Welcome to CodeGolf.SE! You might want to review the FAQ section on questions because your post is a bit underspecified and does not seem to defined a task for which there is an objective winning criterion. Possibly you intend this to be code-golf? If so it should be tagged as such because we support other categories of puzzles and tasks. – dmckee Jul 6 '11 at 19:11

$/=$,;$_=<>;push@$1,$2while/(?=(....)(.))/sg;print+($m)=/(....)/s;print while($m.=($_=m[rand@\$m]))=~s/.//s