Task

Given a jumbled list of the numbers   1   to   9   that are definitely   not   in
ascending order.

Show the list,   and then ask the player how many digits from the
left to reverse.

Reverse those digits,   then ask again,   until all the digits end up in ascending order.



The score is the count of the reversals needed to attain the ascending order.



Note: Assume the player's input does not need extra validation.



Related tasks

   Sorting algorithms/Pancake sort
   Pancake sorting.
   Topswops


 100  LET M$ =  CHR$ (13)
 110  LET A$ = "123456789"
 120  FOR S = 0 TO 1 STEP 0
 130      LET N$ = A$
 140      FOR I = 1 TO 9
 150          LET R =  INT ( RND (1) * 9 + 1)
 160          GOSUB 500SWAP
 170      NEXT I
 180      LET S = N$ <  > A$
 190  NEXT S
 200  FOR S = 1 TO 1E9
 210      PRINT M$"HOW MANY DIGITS "N$M$" FROM THE LEFT  ^^^^^^^^^"M$"  TO REVERSE?   "A$
 230      INPUT "--------------> ";N%
 300      FOR I = 1 TO  INT (N% / 2)
 310          LET R = N% - I + 1
 320          GOSUB 500SWAP
 330      NEXT I
 340      IF N$ = A$ THEN  PRINT M$"SCORE "S;: END 
 350  NEXT S
 500  LET I$ =  MID$ (N$,I,1)
 510  LET N$ =  MID$ (N$,1,I - 1) +  MID$ (N$,R,1) +  MID$ (N$,I + 1)
 520  LET N$ =  MID$ (N$,1,R - 1) + I$ +  MID$ (N$,R + 1)
 530  RETURN 
 