|
Revision 16180, 483 bytes
(checked in by lwall, 19 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 | |
|---|
| 5 | my $n = 2; |
|---|
| 6 | my $m = 10000; |
|---|
| 7 | my %s; |
|---|
| 8 | my $o = 0; |
|---|
| 9 | my @w = "\n" xx $n; # initial state |
|---|
| 10 | |
|---|
| 11 | for $*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"; |
|---|
| 18 | while ($_ = %s{[;] @w}.pick).say { |
|---|
| 19 | last if /\n/ or $o++ >= $m; |
|---|
| 20 | @w.push: $_; @w.shift; # advance chain |
|---|
| 21 | } |
|---|