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.


Perl, 108 chars

What, no answers? Here's a quick Perl solution:

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

And this is what I got the first time I fed the question text through it:

Create a defined. There must also inclined. There must be sure to be according a Markov Chain.

(The average output length should approximately match the input length, so such a short output is quite untypical. On the other hand, the output length is roughly exponentially distributed, so both very short and very long outputs are quite possible.)


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.