Markov chain text generator: Difference between revisions

Added Sidef
(Added Sidef)
Line 1,305:
<pre>$ cargo run "alice_oz.txt" 2 100
to her. The Cat seemed to think about stopping herself before she had never forgotten that, if you will be a coward, said the Caterpillar. Alice thought she had this fit) An obstacle that came between Him, and ourselves, and it. Don't let him know she liked them best, For this must be shutting up like a telescope.' And so she never knew so much at first, but he did was to get him up and said, 'It was the dark to see if the slightest breath of relief, I see we are going to give the Scarecrow and the voice said,</pre>
 
=={{header|Sidef}}==
{{trans|Perl}}
<lang ruby>func build_dict (n, words) {
var dict = Hash()
for i in (0 .. words.len-n) {
var prefix = words.slice(i, i+n-1)
dict{prefix.join(' ')} := [] << words[i+n]
}
return dict
}
 
var file = File(ARGV[0] || "alice_oz.txt")
var n = Num(ARGV[1] || 2)
var max = Num(ARGV[2] || 100)
 
var words = file.open_r.words
var dict = build_dict(n, words)
 
var rotor = words.first(n)
var chain = [rotor...]
 
max.times {
var new = dict{rotor.join(' ')}.rand
chain.push(new)
rotor.shift
rotor.push(new)
}
 
say chain.join(' ')</lang>
 
{{out}}
<pre>
Alice was a large caterpillar, that was linked into hers began to cry a little startled when she knows such a nice little histories about children who had always been used to; but neither were they very small. In fact, they seemed about as she had not been lying on the rocks below. But if you were down here with me! There are wild beasts in the house, quite forgetting that she stamped her foot as far as they moved. The hats of the East and West. Fortunately, the Witches of the fact. 'I keep them back, so they might rest until
</pre>
 
=={{header|Swift}}==
2,756

edits