Execute a Markov algorithm: Difference between revisions
Content added Content deleted
(out tag added in D entry) |
(Added BBC BASIC) |
||
Line 659: | Line 659: | ||
;---------- end of file ----------------------------------------------------</lang> |
;---------- end of file ----------------------------------------------------</lang> |
||
=={{header|BBC BASIC}}== |
|||
<lang bbcbasic> PRINT FNmarkov("ruleset1.txt", "I bought a B of As from T S.") |
|||
PRINT FNmarkov("ruleset2.txt", "I bought a B of As from T S.") |
|||
PRINT FNmarkov("ruleset3.txt", "I bought a B of As W my Bgage from T S.") |
|||
PRINT FNmarkov("ruleset4.txt", "_1111*11111_") |
|||
PRINT FNmarkov("ruleset5.txt", "000000A000000") |
|||
END |
|||
DEF FNmarkov(rulefile$, text$) |
|||
LOCAL i%, done%, rules%, rule$, old$, new$ |
|||
rules% = OPENIN(rulefile$) |
|||
IF rules%=0 ERROR 100, "Cannot open rules file" |
|||
REPEAT |
|||
rule$ = GET$#rules% |
|||
IF ASC(rule$)<>35 THEN |
|||
REPEAT |
|||
i% = INSTR(rule$, CHR$(9)) |
|||
IF i% MID$(rule$,i%,1) = " " |
|||
UNTIL i%=0 |
|||
i% = INSTR(rule$, " -> ") |
|||
IF i% THEN |
|||
old$ = LEFT$(rule$,i%-1) |
|||
WHILE RIGHT$(old$)=" " old$ = LEFT$(old$) : ENDWHILE |
|||
new$ = MID$(rule$,i%+4) |
|||
WHILE ASC(new$)=32 new$ = MID$(new$,2) : ENDWHILE |
|||
IF ASC(new$)=46 new$ = MID$(new$,2) : done% = TRUE |
|||
i% = INSTR(text$,old$) |
|||
IF i% THEN |
|||
text$ = LEFT$(text$,i%-1) + new$ + MID$(text$,i%+LEN(old$)) |
|||
PTR#rules% = 0 |
|||
ENDIF |
|||
ENDIF |
|||
ENDIF |
|||
UNTIL EOF#rules% OR done% |
|||
CLOSE #rules% |
|||
= text$</lang> |
|||
'''Output:''' |
|||
<pre> |
|||
I bought a bag of apples from my brother. |
|||
I bought a bag of apples from T shop. |
|||
I bought a bag of apples with my money from T shop. |
|||
11111111111111111111 |
|||
00011H1111000 |
|||
</pre> |
|||
=={{header|C}}== |
=={{header|C}}== |