Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Collection of Basic Computer Games
#7
Here's an Update for Reverse:
Code: (Select All)
_Title "Reverse Update" 'b+ 2024-07-21 directions 7-22
' compare to Reverse here www.vintage-basic.net/games.html
' David Ahl's compilation of Basic Games and other stuff

'     Directions for Reverse Puzzle:

' Reverse goal is to get the given string of digits back in order from 1 to 9.
' Asking to reverse say 5 will swap first with 5th, 2nd with 4th and that leaves 3 unmoved.
' so   5 4 3 2 1 6 7 8 9 reverse 5
' gets 1 2 3 4 5 6 7 8 9 exactly what we are trying to achieve, you got it!
' reverse always starts on left and counts n to right, note: so reverse 1 does nothing.
'
' Another example from help in original code:
' 2 3 4 5 1 6 7 8 9
' reverse 4
' 5 4 3 2 1 6 7 8 9
' now just reverse 5
' 1 2 3 4 5 6 7 8 9 You got it!
'
' numbers printed on far left are just counting the number of times you use reverse.

Randomize Timer
Dim Shared c$
r$ = " 1 2 3 4 5 6 7 8 9"
c$ = r$
restart:
cnt = 0
fini% = Int(Rnd * 11) + 2
For i = 1 To fini%
    r% = Int(Rnd * 8) + 2
    c$ = reverse$(r%)
Next
Do
    Print cnt, c$
    Input "Enter how many to reverse (0 quits)"; n
    c$ = reverse$(n)
    If c$ = r$ Then Print cnt, c$; " You did it!": Print: Print: Exit Do Else cnt = cnt + 1
Loop
GoTo restart

Function reverse$ (n As Integer)
    If n = 0 Then End
    For i = 1 To 2 * n Step 2
        b$ = Mid$(c$, i, 2) + b$
    Next
    reverse$ = b$ + Mid$(c$, 2 * n + 1)
End Function
b = b + ...
Reply


Messages In This Thread
Collection of Basic Computer Games - by eoredson - 06-16-2024, 03:03 AM
RE: Collection of Basic Computer Games - by bplus - 06-16-2024, 01:23 PM
RE: Collection of Basic Computer Games - by bplus - 07-21-2024, 07:19 PM
RE: Collection of Basic Computer Games - by bplus - 07-21-2024, 11:28 PM
RE: Collection of Basic Computer Games - by bplus - 07-22-2024, 05:41 PM
RE: Collection of Basic Computer Games - by bplus - 07-22-2024, 06:54 PM



Users browsing this thread: 2 Guest(s)