Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
55
Task/Number-reversal-game/BASIC/number-reversal-game.basic
Normal file
55
Task/Number-reversal-game/BASIC/number-reversal-game.basic
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
PRINT "Given a jumbled list of the numbers 1 to 9,"
|
||||
PRINT "you must select how many digits from the left to reverse."
|
||||
PRINT "Your goal is to get the digits in order with 1 on the left and 9 on the right."
|
||||
|
||||
RANDOMIZE TIMER
|
||||
|
||||
DIM nums(1 TO 9) AS INTEGER
|
||||
DIM L0 AS INTEGER, n AS INTEGER, flp AS INTEGER, tries AS INTEGER, again AS INTEGER
|
||||
|
||||
'initial values
|
||||
FOR L0 = 1 TO 9
|
||||
nums(L0) = L0
|
||||
NEXT
|
||||
|
||||
DO 'shuffle
|
||||
FOR L0 = 9 TO 2 STEP -1
|
||||
n = INT(RND * (L0)) + 1
|
||||
IF n <> L0 THEN SWAP nums(n), nums(L0)
|
||||
NEXT
|
||||
FOR L0 = 1 TO 8 'make sure it's not in order
|
||||
IF nums(L0) > nums(L0 + 1) THEN EXIT DO
|
||||
NEXT
|
||||
LOOP
|
||||
|
||||
again = -1
|
||||
DO
|
||||
IF tries < 10 THEN PRINT " ";
|
||||
PRINT tries; ":";
|
||||
FOR L0 = 1 TO 9
|
||||
PRINT nums(L0);
|
||||
NEXT
|
||||
|
||||
IF NOT again THEN EXIT DO
|
||||
|
||||
INPUT " -- How many numbers should be flipped"; flp
|
||||
IF flp < 0 THEN flp = 0
|
||||
IF flp > 9 THEN flp = 0
|
||||
|
||||
FOR L0 = 1 TO (flp \ 2)
|
||||
SWAP nums(L0), nums(flp - L0 + 1)
|
||||
NEXT
|
||||
|
||||
again = 0
|
||||
'check for order
|
||||
FOR L0 = 1 TO 8
|
||||
IF nums(L0) > nums(L0 + 1) THEN
|
||||
again = -1
|
||||
EXIT FOR
|
||||
END IF
|
||||
NEXT
|
||||
|
||||
IF flp > 0 THEN tries = tries + 1
|
||||
LOOP
|
||||
|
||||
PRINT : PRINT "You took "; LTRIM$(RTRIM$(STR$(tries))); " tries to put the digits in order."
|
||||
Loading…
Add table
Add a link
Reference in a new issue