Jump to content

Execute a Markov algorithm: Difference between revisions

m (→‎Ruleset 1: Missing tag)
Line 130:
 
=Examples=
=={{header|AutoHotkey}}==
{{in progress|lang=AutoHotkey|day=24|month=12|year=2009}}
<lang ahk>#Persistent
#SingleInstance, OFF
SetBatchLines, -1
StringCaseSense, On
Gui, +OwnDialogs
Gui, Add, CheckBox, w500 vVerbose, Verbose?
Gui, Add, Edit, w500 h250 vRules Center +WantReturn +WantTab, Rules
Gui, Add, Button, w500 gMarkov, Markov It!
Gui, Add, Edit, w500 h250 vString Center +WantReturn +WantTab, String
Gui, Show,, Markov Algorithm RosettaCode Example
Return
Markov:
Gui, Submit, NoHide
StringReplace, Rules, Rules, `r,, All
Loop, parse, Rules, `n
{
If (!A_LoopField || RegExMatch(A_LoopField, "Um)^[ \t]*#.*$"))
Continue
If (RegExMatch(A_LoopField, "Um)^(.+)[ \t]*->[ \t]*(\.?)(.*)$", _) = 0)
{
MsgBox, 4, Markov Algorithm - ERROR, You have an error in your ruleset on line %A_Index%. Ignore line and continue?
IfMsgBox, No
Return
Continue
}
_1 := _1
_3 := _3
StringReplace, String, String, %_1%, %_3%
While !ErrorLevel
StringReplace, String, String, %_1%, %_3%
If Verbose
Out .= A_Index . ": " . String . "`n"
If (_2 = ".")
Break
}
If Verbose
MsgBox,, Markov Algorithm, %Out%
Else
MsgBox,, Markov Algorithm, %String%
Return
GuiClose:
ExitApp</lang>
 
=={{header|C}}==
 
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.