Anonymous user
Bulls and cows: Difference between revisions
→{{header|Elena}}
m (→version 1: added whitespace to the output.) |
|||
Line 1,357:
=={{header|Elena}}==
ELENA 3.
<lang elena>import system'routines.
import extensions.
Line 1,370:
// generate secret number
var aRandomNumbers := (1,2,3,4,5,6,7,8,9) randomize:9.
theNumbers := aRandomNumbers Subarray:4
theAttempt := Integer new:1.
]
Line 1,377:
ask
[
var aRow := console print
^ aRow toArray.
Line 1,390:
[ aBulls append int:(-1). ];
[
try(0 to:3
[
var ch := aGuess
var aNumber := ch literal; toInt.
Line 1,400:
// check duplicates
var duplicate := aGuess
if ($nil != duplicate)
[
InvalidArgumentException new; raise.
].
if (aNumber == theNumbers
[ aBulls append int:1 ];
[
Line 1,414:
])
{
[
aBulls int := -1
Line 1,421:
].
-1 [ console
4 [ console
! [
theAttempt append int:1.
console printLine
^ true
|