How to resolve the algorithm Number reversal game step by step in the PicoLisp programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Number reversal game step by step in the PicoLisp 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 PicoLisp programming language
Source code in the picolisp programming language
(load "@lib/simul.l")
(de reversalGame ()
(let (Lst (shuffle (range 1 9)) Cnt 0)
(while (apply < Lst)
(setq Lst (shuffle Lst)) )
(loop
(printsp Lst)
(T (apply < Lst) Cnt)
(NIL (num? (read)))
(setq Lst (flip Lst @))
(inc 'Cnt) ) ) )
You may also check:How to resolve the algorithm Bitmap/Midpoint circle algorithm step by step in the Ruby programming language
You may also check:How to resolve the algorithm Animation step by step in the M2000 Interpreter programming language
You may also check:How to resolve the algorithm Variables step by step in the FreeBASIC programming language
You may also check:How to resolve the algorithm Boolean values step by step in the XPL0 programming language
You may also check:How to resolve the algorithm Rot-13 step by step in the Sidef programming language