RosettaCodeData/Task/Number-reversal-game/Run-BASIC/number-reversal-game.basic
2023-07-01 13:44:08 -04:00

40 lines
760 B
Text

for i = 1 to 9 ' get numbers 1 to 9
n(i) = i
next i
numShuffles = 3
' ----------------------------------
' shuffle numbers
' ----------------------------------
for i = 1 to 9 * numShuffles
i1 = int(rnd(1)*9) + 1
i2 = int(rnd(1)*9) + 1
h2 = n(i1)
n(i1) = n(i2)
n(i2) = h2
next i
for i = 1 to 9
a$ = a$ + str$(n(i)) + " "
next i
count = 0
[loop]
count = count + 1
print count;" : ";a$
for i = 1 to 9 ' check if in sequence
j = i * 2
if mid$(a$,j-1,1) > mid$(a$,j,1) then goto [notOrdered]
next i
print "It took ";count;" tries"
end
[notOrdered]
input "How many numbers to flip:";i
i = ((i-1) * 2) + 1
b$ = ""
for j = i to 1 step -2
b$ = b$ + mid$(a$,j,2)
next j
a$ = b$ + mid$(a$,i + 2)
goto [loop]
end