Anonymous user
Execute a Markov algorithm: Difference between revisions
m
→{{header|REXX}}: added/changed comments and whitespace, used a template for the output and ruleset 6; use a right arrow string instead of equivalence character.
(→{{header|Kotlin}}: Changed 'do' loop to avoid use of label + removed surplus whitespace) |
m (→{{header|REXX}}: added/changed comments and whitespace, used a template for the output and ruleset 6; use a right arrow string instead of equivalence character.) |
||
Line 3,443:
Code was added to the REXX example to optionally list the contents of the ruleset and/or the Markov entries.
<br>Also, blank lines in the ruleset were treated as comments.
<lang rexx>/*REXX program executes a Markov algorithm(s) against specified entries. */
parse arg low high . /*allows which ruleset to process. */
if low=='' | low==
if high=='' | high==
tellE= low<0; tellR= high<0 /*flags: used to display file contents.*/
call readEntry
do j=abs(low) to abs(high) /*process each of these rulesets. */
call readRules j /*read a particular ruleset. */
call execRules j /*execute " " " */
say 'result for ruleset' j "
end /*j*/
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
execRules: parse arg q .; if tellE | tellR then say /*show a blank line?*/
do f=1
do k=1 while @.k\==''; if left(@.k, 1)=='#' | @.k='' then iterate
parse var @.k a ' ->' b
if fullstop then if old\==!.q then
if old\==!.q then iterate f /*Has Entry changed? Then start over.*/
end /*k*/▼
return
/*──────────────────────────────────────────────────────────────────────────────────────*/
readRules: parse arg ? .; rFID='MARKOV_R.'?; if tellR then say▼
do e=1 while lines(eFID)\==0 /*read the input file until End-Of-File*/
return
/*──────────────────────────────────────────────────────────────────────────────────────*/
▲!.= /*placeholder for all the test entries.*/
do r=1 while lines(rFID)\==0 /*read the input file until End-Of-File*/
end /*r*/ /* [↑] read and maybe echo the rule. */
return</lang>
Some older REXXes don't have a '''changestr''' BIF, so one is included here ──► [[CHANGESTR.REX]].
<br><br>
<pre>
result for ruleset
result for ruleset
result for ruleset
result for ruleset
result for ruleset
result for ruleset
</pre>
<pre>
# Rewrite binary numbers to their unary value (| bars).
|