How to resolve the algorithm Number reversal game step by step in the TUSCRIPT programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Number reversal game step by step in the TUSCRIPT programming language
Table of Contents
Problem Statement
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.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Number reversal game step by step in the TUSCRIPT programming language
Source code in the tuscript programming language
$$ MODE TUSCRIPT
numbers=RANDOM_NUMBERS (1,9,9),nr=0
SECTION check
LOOP o,n=numbers
IF (n!=o) THEN
DO PRINT
EXIT
ELSEIF (n==9&&o==9) THEN
DO PRINT
PRINT " You made it ... in round ",r
STOP
ELSE
CYCLE
ENDIF
ENDLOOP
ENDSECTION
SECTION print
PRINT numbers
ENDSECTION
DO PRINT
LOOP r=1,14
IF (nr>=0&&nr<10) THEN
ASK "Reverse - how many?": nr=""
i=""
LOOP n=1,nr
i=APPEND(i,n)
ENDLOOP
numbers =SPLIT (numbers)
reverse_nr=SELECT (numbers,#i,keep_nr), reverse_nr=REVERSE(reverse_nr)
numbers =APPEND (reverse_nr,keep_nr), numbers =JOIN (numbers)
DO check
ENDIF
ENDLOOP
You may also check:How to resolve the algorithm Hash join step by step in the Scheme programming language
You may also check:How to resolve the algorithm Equilibrium index step by step in the Fortran programming language
You may also check:How to resolve the algorithm Averages/Median step by step in the Icon and Unicon programming language
You may also check:How to resolve the algorithm Arithmetic-geometric mean step by step in the Erlang programming language
You may also check:How to resolve the algorithm Sort an integer array step by step in the FreeBASIC programming language