Jump to content

Bulls and cows: Difference between revisions

m (→‎{{header|Sidef}}: minor code correction)
Line 952:
{
#field theNumbers.
#field theAttempt.
 
#constructor new
[
// generate secret number
#var aRandomNumbers := randomControl randomize:9 &array:(1,2,3,4,5,6,7,8,9).
theNumbers := arrayControl Subarray:aRandomNumbers &from:0 &length:4.
theAttempt := Integer new:1.
]
 
#method ask
[
#var aRow := consoleEx write:"Your Guess #":theAttempt:" ?" readLine.
^ literalControl toArray:aRow.
Line 976 ⟶ 977:
? [ aBulls << -1. ]
! [
control fromforrange &int:0 &toint:3 &do: (&int:i)
[
#var ch := aGuess@i.
Line 1,009 ⟶ 1,010:
4 ? [ consoleEx writeLine:"Congratulations! You have won!". ^ false. ]
! [
theAttempt += 1.
consoleEx writeLine:"Your Score is " : aBulls : " bulls and " : aCows : " cows".
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.