root/examples/markov.pl

Revision 16180, 483 bytes (checked in by lwall, 20 months ago)

[markov.pl] typo

Line 
1#!/usr/bin/pugs
2#Simple Markov chain Dissociated Press implementation
3#adapted from http://cm.bell-labs.com/cm/cs/tpop/markov.pl
4
5my $n = 2;
6my $m = 10000;
7my %s;
8my $o = 0;
9my @w = "\n" xx $n;                     # initial state
10
11for $*ARGS.comb {                       # read each word of input
12        %s{[;] @w}.push: $_;
13        @w.push: $_; @w.shift;          # advance chain
14}
15%s{[;] @w}.push: "\n";                  # add tail
16
17@w »=» "\n";
18while ($_ = %s{[;] @w}.pick).say {
19        last if /\n/ or $o++ >= $m;
20        @w.push: $_; @w.shift;          # advance chain
21}
Note: See TracBrowser for help on using the browser.