diff options
Diffstat (limited to 'markov.lpr')
-rw-r--r-- | markov.lpr | 22 |
1 files changed, 12 insertions, 10 deletions
@@ -8,14 +8,14 @@ uses {$ENDIF}{$ENDIF} Classes { you can add units after this }, - sysutils, math; + sysutils, math, mystringlistunit; var wordFileName,s: string; count: longint; depth,i,j,current: int64; c: char; - f: textFile; + f: tMyStringList; probabilities: array of extended; total: extended; c2i: array[char] of longint; @@ -67,10 +67,9 @@ begin for i:=0 to length(probabilities)-1 do probabilities[i]:=0; - assignFile(f,wordFileName); - reset(f); - while not eof(f) do begin - readln(f,s); + f:=tMyStringList.create; + f.loadFromFile(wordFileName); + while f.readln(s) do begin s:=s+' '; // lf ends a word, too current:=0; // reset current index for i:=1 to length(s) do begin @@ -85,7 +84,6 @@ begin probabilities[current]:=probabilities[current]+1; end; end; - closeFile(f); for i:=0 to length(probabilities) div (length(i2c)+1)-1 do begin total:=0; @@ -115,6 +113,7 @@ begin // generation while count>0 do begin current:=0; + s:=''; repeat current:=current * (length(i2c)+1) mod length(probabilities); total:=random; @@ -126,12 +125,15 @@ begin if current mod (length(i2c)+1) = 0 then break else - write(i2c[current mod (length(i2c)+1)]); + s:=s+i2c[current mod (length(i2c)+1)]; until false; - writeln; - dec(count); + if not f.hatZeile(s,false) then begin; + writeln(s); + dec(count); + end; end; + f.free; setLength(probabilities,0); end. |