Markov chain text generator: Difference between revisions
Content deleted Content added
→{{header|REXX}}: added the REXX computer programming language. |
→{{header|REXX}}: optimized the building of the prefix table. |
||
Line 916:
sw = linesize() - 1 /*get usable linesize (screen width). */
$= space( linein(iFID) ) /*elide any superfluous whitespace in $*/
$$= $ /*save a copy after $ is destructed. */
say words($) ' words read from input file: ' iFID
call gTab /*generate the Markov chain text table.*/
Line 925 ⟶ 926:
/*──────────────────────────────────────────────────────────────────────────────────────*/
gTab: @.=; do j=1 for words($)-ord /*keep processing until words exhausted*/
p= subword($,
@.p= @.p word($, ord) /*build prefix & 1 (of sev.?) suffixes.*/
end /*j*/
#= j-1 /*define the number of prefixes. */
Line 932 ⟶ 934:
/*──────────────────────────────────────────────────────────────────────────────────────*/
gTxt: mc=; do until words(mc)>=fin /*build Markov chain text until enough.*/
y= subword($$, rand(#), ord)
s= @.y; w= words(s) /*get a suffix for a word set; # wprds.*/
if w>1 then s= word(s, rand(w)) /*pick random word in the set of words.*/
Line 947 ⟶ 949:
end /*k*/
if g\=='' then say g /*There any residual? Then display it.*/
return /* [
{{out|output|text= when using the default inputs:}}
<pre>
════════════════════════════════════════════════════════Markov chain text════════════════════════════════════════════════════════
great Head? That was fell out of the the Caterpillar. 'Well, I've her crows and her us, he said, built eyes so often with quiet
till she got Tin Woodman were glad my body, splitting me said Alice, very much long arms growing out her and bit her before she
had drunk tremble. Quick! cried the a low, trembling voice. corner, but the Rabbit never heard it before,' small point a foot in
a little rippling the little girl was silver whistle twice. Straightway in groups. But the green leaves that lay well! It means
much who ran to Alice said the Cowardly Lion, Palace for several days, head and arms and say How doth the the effect: the next
her; so I set not doing these little saw no one at who played with Toto So the Scarecrow followed have witches and wizards
people to keep away ropes, and the balloon added to one of answered Oz. But I if you don't mind, for them. They came her in any
way. that it might happen Hatter said, turning to at the water's edge. anything to say, she Are you going with it a kind heart?
still in existence; 'and of speaking to a of tin. After this was as big as From the Land of it with hot air. The country here is
and frightening my cow? a coward. Have you upon it.) 'I'm glad creeping back, and Toto But Dorothy they did grin, and she said
for one so cowardly. but I think I dear! Let this be Dorothy and Toto and it's an arm, yer sent the soldier with what to do with
a mouse: she had not think of any their paws. 'And how I will fight them there were two little Making believe! cried Dorothy.
</pre>
|