How to resolve the algorithm Best shuffle step by step in the Action! programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Best shuffle step by step in the Action! programming language
Table of Contents
Problem Statement
Shuffle the characters of a string in such a way that as many of the character values are in a different position as possible. A shuffle that produces a randomized result among the best choices is to be preferred. A deterministic approach that produces the same sequence every time is acceptable as an alternative. Display the result as follows: The score gives the number of positions whose character value did not change.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Best shuffle step by step in the Action! programming language
Source code in the action! programming language
PROC BestShuffle(CHAR ARRAY orig,res)
BYTE i,j,len
CHAR tmp
len=orig(0)
SCopy(res,orig)
FOR i=1 TO len
DO
FOR j=1 TO len
DO
IF i#j AND orig(i)#res(j) AND orig(j)#res(i) THEN
tmp=res(i) res(i)=res(j) res(j)=tmp
FI
OD
OD
RETURN
PROC Test(CHAR ARRAY orig)
CHAR ARRAY res(100)
BYTE i,score
BestShuffle(orig,res)
score=0
FOR i=1 TO orig(0)
DO
IF orig(i)=res(i) THEN
score==+1
FI
OD
PrintF("%S, %S, (%B)%E",orig,res,score)
RETURN
PROC Main()
Test("abracadabra")
Test("seesaw")
Test("elk")
Test("grrrrrr")
Test("up")
Test("a")
RETURN
You may also check:How to resolve the algorithm HTTP step by step in the Scheme programming language
You may also check:How to resolve the algorithm Non-decimal radices/Output step by step in the Lua programming language
You may also check:How to resolve the algorithm Non-decimal radices/Convert step by step in the XPL0 programming language
You may also check:How to resolve the algorithm Totient function step by step in the FreeBASIC programming language
You may also check:How to resolve the algorithm Isograms and heterograms step by step in the Wren programming language