Number reversal game: Difference between revisions

Added BBC BASIC
m (→‎{{header|REXX}}: added comment, added whitespace to concatenation operation. -- ~~~~)
(Added BBC BASIC)
Line 280:
7 : 1 2 3 4 5 6 7 8 9
You took 7 tries to put the digits in order.
 
=={{header|BBC BASIC}}==
Note the use of the MOD(array()) function to test the equality of two arrays.
<lang bbcbasic> DIM list%(8), done%(8), test%(8)
list%() = 1, 2, 3, 4, 5, 6, 7, 8, 9
done%() = list%()
REM Shuffle:
FOR i% = 9 TO 2 STEP -1
SWAP list%(i%-1), list%(RND(i%)-1)
NEXT
REM Run the game:
tries% = 0
REPEAT
tries% += 1
FOR i% = 0 TO 8 : PRINT ; list%(i%) " " ; : NEXT
INPUT ": Reverse how many", n%
PROCreverse(list%(), n%)
test%() = list%() - done%()
UNTIL MOD(test%()) = 0
PRINT "You took " ; tries% " attempts."
END
DEF PROCreverse(a%(), n%)
IF n% < 2 ENDPROC
LOCAL i%
n% -= 1
FOR i% = 0 TO n% DIV 2
SWAP a%(i%), a%(n%-i%)
NEXT
ENDPROC</lang>
'''Output:'''
<pre>
7 2 3 1 5 8 6 4 9 : Reverse how many? 6
8 5 1 3 2 7 6 4 9 : Reverse how many? 8
4 6 7 2 3 1 5 8 9 : Reverse how many? 3
7 6 4 2 3 1 5 8 9 : Reverse how many? 7
5 1 3 2 4 6 7 8 9 : Reverse how many? 5
4 2 3 1 5 6 7 8 9 : Reverse how many? 4
1 3 2 4 5 6 7 8 9 : Reverse how many? 3
2 3 1 4 5 6 7 8 9 : Reverse how many? 2
3 2 1 4 5 6 7 8 9 : Reverse how many? 3
You took 9 attempts.
</pre>
 
=={{header|Brat}}==