Bulls and cows: Difference between revisions
Content deleted Content added
Underscore (talk | contribs) m →{{header|Coco}}: Changed some `==`s to `===`s. |
→{{header|AutoHotkey}}: add function + feedback |
||
Line 142:
=={{header|AutoHotkey}}==
<lang autohotkey>
Random, num, 1, 9▼
While StrLen(Code) < length {
If !InStr(Code, num)▼
Code .= num▼
}
Gui, Add, Text, w83 vInfo, I'm thinking of a %length%-digit number with no duplicate digits.
Gui, Add,
Gui, Add,
Gui, Add, Edit, ym w130 r8 vHistory ReadOnly
Gui, Show
Return
ButtonSubmit:
If Default = Restart
Gui, Submit, NoHide▼
Reload
If StrLen(Guess) != 4▼
GuiControl, , Info, Enter a %length%-digit number.
Else If Guess is not digit
GuiControl, , Info, Enter a %length%-digit number.
Else
If (SubStr(Guess, A_Index, 1) = SubStr(Code, A_Index, 1))▼
{
GuiControl, , Info
Else If InStr(Code, SubStr(Guess, A_Index, 1))▼
GuiControl, , Guess
GuiControl,, History, % Guess ": " bulls " Bulls " cows " Cows"▼
{
GuiControl, , Info, Correct!
GuiControl, , Default, Restart
Default = Restart
}
response := Response(Guess, Code)
Bulls := SubStr(response, 1, InStr(response,",")-1)
Cows := SubStr(response, InStr(response,",")+1)
}
Return
GuiEscape:
GuiClose:
Response(Guess,Code) {
Bulls := 0, Cows := 0
Loop, % StrLen(Code)
Bulls++
Cows++
Return Bulls "," Cows
}</lang>
=={{header|BASIC}}==
|