[t/spec] A few wilder tests for nesting.
[pugs.git] / examples / markov.pl
blobdc281b32801791ba2e5902746cbd69776b696049
1 #!/usr/bin/pugs
2 #Simple Markov chain Dissociated Press implementation
3 #adapted from http://cm.bell-labs.com/cm/cs/tpop/markov.pl
5 my $n = 2;
6 my $m = 10000;
7 my %s;
8 my $o = 0;
9 my @@w = "\n" xx $n; # initial state
11 for $*ARGS.comb { # read each word of input
12 %s{@@w}.push: $_;
13 @@w.push: $_; @@w.shift; # advance chain
15 %s{@@w}.push: "\n"; # add tail
17 @@w = "\n" xx *;
18 while ($_ = %s{@@w}.pick).say {
19 last if /\n/ or $o++ >= $m;
20 @@w.push: $_; @@w.shift; # advance chain