/ Published in: Perl
My PERL isn't strong enough to get this yet, but I plan on porting to C#.
Read this: http://en.wikipedia.org/wiki/Markov_chain
Read this: http://en.wikipedia.org/wiki/Markov_chain
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
# Copyright (C) 1999 Lucent Technologies # Excerpted from 'The Practice of Programming' # by Brian W. Kernighan and Rob Pike # markov.pl: markov chain algorithm for 2-word prefixes $MAXGEN = 10000; $NONWORD = "\n"; $w1 = $w2 = $NONWORD; # initial state while (<>) { # read each line of input { ($w1, $w2) = ($w2, $_); # multiple assignment } } $w1 = $w2 = $NONWORD; for ($i = 0; $i < $MAXGEN; $i++) { $suf = $statetab{$w1}{$w2}; # array reference ($w1, $w2) = ($w2, $t); # advance chain }
URL: http://www.beetleinabox.com/markov.html