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: | Line 142: | ||
=={{header|AutoHotkey}}== |
=={{header|AutoHotkey}}== |
||
<lang autohotkey> |
<lang autohotkey>length:=4, Code:="" ; settings |
||
⚫ | |||
While StrLen(Code) < length { |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
} |
} |
||
Gui, Add, Text, w83 vInfo, I'm thinking of a %length%-digit number with no duplicate digits. |
|||
Gui, Add, Edit, vGuess, Enter a guess... |
|||
Gui, Add, |
Gui, Add, Edit, wp vGuess, Enter a guess... |
||
Gui, Add, |
Gui, Add, Button, wp Default vDefault, Submit |
||
Gui, Add, Edit, ym w130 r8 vHistory ReadOnly |
|||
Gui, Show |
Gui, Show |
||
Return |
Return |
||
ButtonSubmit: |
ButtonSubmit: |
||
If Default = Restart |
|||
⚫ | |||
Reload |
|||
⚫ | |||
⚫ | |||
Return |
|||
If (StrLen(Guess) != length) |
|||
GuiControl, , Info, Enter a %length%-digit number. |
|||
Return |
|||
Else If Guess is not digit |
|||
bulls:=0, cows:=0 |
|||
GuiControl, , Info, Enter a %length%-digit number. |
|||
Loop, 4 |
|||
Else |
|||
⚫ | |||
{ |
|||
bulls++ |
|||
GuiControl, , Info |
|||
⚫ | |||
GuiControl, , Guess |
|||
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 |
Return |
||
GuiEscape: |
|||
GuiClose: |
GuiClose: |
||
ExitApp |
|||
Response(Guess,Code) { |
|||
Bulls := 0, Cows := 0 |
|||
Loop, % StrLen(Code) |
|||
⚫ | |||
Bulls++ |
|||
⚫ | |||
Cows++ |
|||
Return Bulls "," Cows |
|||
}</lang> |
|||
=={{header|BASIC}}== |
=={{header|BASIC}}== |