Jump to content

Markov chain text generator: Difference between revisions

Changed the way to display the text splitting it to avoid lines longer than a limit.
(Added missing <lang Nim>)
(Changed the way to display the text splitting it to avoid lines longer than a limit.)
Line 939:
 
result = output[0..<outputSize].join(" ")
 
 
const MaxLineSize = 100
 
randomize()
echolet result = markov("alice_oz.txt", 3, 100)</lang>
var start = 0
while start < result.len:
var idx = if start + MaxLineSize <= result.high: result.rfind(' ', start, start + MaxLineSize)
else: result.high
if idx < 0: idx = result.high
echo result[start..idx]
start = idx + 1</lang>
 
{{out}}
<pre>ground was carpeted with them. There were big yellow and white and blue and purple blossoms, besides
<pre>soon made up her mind to wear it and carry her sunbonnet in the basket. But the Scarecrow said, We cannot fly, that is certain. Neither can we climb down into this great ditch. Therefore, if we cannot get to the door. 'Call the next witness.' And he added in an undertone to the Queen, 'Really, my dear, you will have the castle to yourself. I have been making believe. Making believe! cried Dorothy. Are you a Munchkin? asked Dorothy. No, for this pole is stuck up my back. If you will come with me I'll ask Oz to do</pre>
great clusters of scarlet poppies, which were so brilliant in color they almost dazzled Dorothy's
eyes. Aren't they beautiful? the girl asked, as she breathed in the spicy scent of the flowers, and
here they laid her gently on the forehead. Where her lips touched the girl they left a round,
shining mark, as Dorothy found out soon after. The road to the City of Emeralds. Perhaps Oz will
help you. Where is this great spider of yours now? asked the Tin Woodman.</pre>
 
=={{header|Perl}}==
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.