How to resolve the algorithm Compare a list of strings step by step in the XProfan programming language
How to resolve the algorithm Compare a list of strings step by step in the XProfan programming language
Table of Contents
Problem Statement
Given a list of arbitrarily many strings, show how to:
Each of those two tests should result in a single true or false value, which could be used as the condition of an if statement or similar. If the input list has less than two elements, the tests should always return true. There is no need to provide a complete program and output. Assume that the strings are already stored in an array/list/sequence/tuple variable (whatever is most idiomatic) with the name strings, and just show the expressions for performing those two tests on it (plus of course any includes and custom functions etc. that it needs), with as little distractions as possible. Try to write your solution in a way that does not modify the original list, but if it does then please add a note to make that clear to readers. If you need further guidance/clarification, see #Perl and #Python for solutions that use implicit short-circuiting loops, and #Raku for a solution that gets away with simply using a built-in language feature.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Compare a list of strings step by step in the XProfan programming language
Source code in the xprofan programming language
Proc allsame
Parameters long liste
var int result = 1
var int cnt = GetCount(liste)
Case cnt == 0 : Return 0
Case cnt == 1 : Return 1
WhileLoop 1, cnt-1
If GetString$(liste,&loop - 1) <> GetString$(liste,&loop)
result = 0
BREAK
EndIf
EndWhile
Return result
EndProc
Proc strict_order
Parameters long liste
var int result = 1
var int cnt = GetCount(liste)
Case cnt == 0 : Return 0
Case cnt == 1 : Return 1
WhileLoop 1, cnt-1
If GetString$(liste,&loop) <= GetString$(liste,&loop - 1)
result = 0
BREAK
EndIf
EndWhile
Return result
EndProc
cls
declare string s[4]
s[0] = "AA,BB,CC"
s[1] = "AA,AA,AA"
s[2] = "AA,CC,BB"
s[3] = "AA,ACB,BB,CC"
s[4] = "single_element"
WhileLoop 0,4
ClearList 0
Move("StrToList",s[&loop],",")
Print "list:",s[&loop]
Print "...is " + if(allsame(0), "", "not ") + "lexically equal"
Print "...is " + if(strict_order(0), "", "not ") + "in strict ascending order"
EndWhile
ClearList 0
WaitKey
end
You may also check:How to resolve the algorithm LZW compression step by step in the Picat programming language
You may also check:How to resolve the algorithm Random numbers step by step in the Maxima programming language
You may also check:How to resolve the algorithm Loops/With multiple ranges step by step in the FreeBASIC programming language
You may also check:How to resolve the algorithm Mandelbrot set step by step in the Mathematica / Wolfram Language programming language
You may also check:How to resolve the algorithm Comments step by step in the Asymptote programming language