7
\$\begingroup\$

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.

\$\endgroup\$
  • 1
    \$\begingroup\$ Can you explain more and give sample I/O? I don't really understand the challenge. \$\endgroup\$ – Peter Olson Jul 6 '11 at 18:40
  • 1
    \$\begingroup\$ @Peter Take a look at en.wikipedia.org/wiki/Markov_chain#Markov_text_generators \$\endgroup\$ – Cyclone Jul 6 '11 at 19:08
  • 4
    \$\begingroup\$ 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. \$\endgroup\$ – dmckee Jul 6 '11 at 19:11
3
\$\begingroup\$

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.)

\$\endgroup\$

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.