How to resolve the algorithm Number reversal game step by step in the HicEst programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Number reversal game step by step in the HicEst 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 HicEst programming language
Source code in the hicest programming language
WRITE(Messagebox) "You took ", Reversals(), " attempts"
FUNCTION Reversals()
DIMENSION digits(9), temp(9)
digits = 0
DO i = 1, 9 ! create the shuffled digits
1 x = CEILING( RAN(9) )
IF( INDEX(digits, x) ) GOTO 1 ! HicEst has no WHILE
digits(i) = x
ENDDO
DO Reversals = 1, 1E6 ! HicEst needs an upper bound
DLG(NameEdit=Flips, DNum, MIn=0, MAx=9, Text=digits)
DO j = 1, Flips/2
swap = digits(j)
digits(j) = digits(Flips+1-j)
digits(Flips+1-j) = swap
ENDDO
temp = digits($+1) > digits($) ! $ = left side index
IF( SUM(temp) == 8 ) RETURN
ENDDO
END
You may also check:How to resolve the algorithm One of n lines in a file step by step in the C++ programming language
You may also check:How to resolve the algorithm Galton box animation step by step in the Phix programming language
You may also check:How to resolve the algorithm Permutations/Derangements step by step in the Haskell programming language
You may also check:How to resolve the algorithm Evaluate binomial coefficients step by step in the R programming language
You may also check:How to resolve the algorithm Linear congruential generator step by step in the Run BASIC programming language