Compare a list of strings: Difference between revisions

m
 
(45 intermediate revisions by 31 users not shown)
Line 26:
=={{header|11l}}==
{{trans|D}}
<langsyntaxhighlight lang="11l">L(strings_s) [‘AA AA AA AA’, ‘AA ACB BB CC’]
V strings = strings_s.split(‘ ’)
print(strings)
print(all(zip(strings, strings[1..]).map(a -> a[0] == a[1])))
print(all(zip(strings, strings[1..]).map(a -> a[0] < a[1])))
print()</langsyntaxhighlight>
 
=={{header|360 Assembly}}==
The program uses one ASSIST macro (XPRNT) to keep the code as short as possible.
<langsyntaxhighlight lang="360asm">* Compare a list of strings 31/01/2017
COMPLIST CSECT
USING COMPLIST,R13 base register
Line 122:
PG DS CL80
YREGS
END COMPLIST</langsyntaxhighlight>
{{out}}
<pre>
Line 128:
AAA : all elements are equal
ACB : neither equal nor in increasing order
</pre>
 
=={{header|Action!}}==
<syntaxhighlight lang="action!">DEFINE PTR="CARD"
 
BYTE FUNC AreEqual(PTR ARRAY a BYTE len)
INT i
 
FOR i=1 TO len-1
DO
IF SCompare(a(0),a(i))#0 THEN
RETURN (0)
FI
OD
RETURN (1)
 
BYTE FUNC IsAscendingOrder(PTR ARRAY a BYTE len)
INT i
 
FOR i=1 TO len-1
DO
IF SCompare(a(i-1),a(i))>=0 THEN
RETURN (0)
FI
OD
RETURN (1)
 
PROC Test(PTR ARRAY a BYTE len)
INT i
 
Print("Input array: [")
FOR i=0 TO len-1
DO
Print(a(i))
IF i<len-1 THEN
Put(32)
FI
OD
PrintE("]")
 
IF AreEqual(a,len) THEN
PrintE("All strings are lexically equal.")
ELSE
PrintE("Not all strings are lexically equal.")
FI
 
IF IsAscendingOrder(a,len) THEN
PrintE("The list is in strict ascending order.")
ELSE
PrintE("The list is not in strict ascending order.")
FI
PutE()
RETURN
 
PROC Main()
PTR ARRAY a1(4),a2(4),a3(4),a4(1)
 
a1(0)="aaa" a1(1)="aaa" a1(2)="aaa" a1(3)="aaa"
Test(a1,4)
 
a2(0)="aaa" a2(1)="aab" a2(2)="aba" a2(3)="baa"
Test(a2,4)
 
a3(0)="aaa" a3(1)="aab" a3(2)="aba" a3(3)="aba"
Test(a3,4)
 
a4(0)="aaa"
Test(a4,1)
RETURN</syntaxhighlight>
{{out}}
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Compare_a_list_of_strings.png Screenshot from Atari 8-bit computer]
<pre>
Input array: [aaa aaa aaa aaa]
All strings are lexically equal.
The list is not in strict ascending order.
 
Input array: [aaa aab aba baa]
Not all strings are lexically equal.
The list is in strict ascending order.
 
Input array: [aaa aab aba aba]
Not all strings are lexically equal.
The list is not in strict ascending order.
 
Input array: [aaa]
All strings are lexically equal.
The list is in strict ascending order.
</pre>
 
Line 133 ⟶ 220:
 
We will store the "list" of strings in a vector. The vector will hold "indefinite" strings, i.e., the strings can have different lengths.
<langsyntaxhighlight Adalang="ada"> package String_Vec is new Ada.Containers.Indefinite_Vectors
(Index_Type => Positive, Element_Type => String);
use type String_Vec.Vector;</langsyntaxhighlight>
 
The equality test iterates from the first to the last-but one index. For index Idx,
Line 142 ⟶ 229:
yes for any Idx, the function immediately returns False. If the answer is no for all Idx,
the function finally returns True.
<langsyntaxhighlight Adalang="ada"> function All_Are_The_Same(Strings: String_Vec.Vector) return Boolean is
begin
for Idx in Strings.First_Index .. Strings.Last_Index-1 loop
Line 150 ⟶ 237:
end loop;
return True;
end All_Are_The_Same;</langsyntaxhighlight>
 
Similarily, the strictly ascending test checks if Strings(Idx) is greater or equal Strings(Idx+1).
<langsyntaxhighlight Adalang="ada"> function Strictly_Ascending(Strings: String_Vec.Vector) return Boolean is
begin
for Idx in Strings.First_Index+1 .. Strings.Last_Index loop
Line 161 ⟶ 248:
end loop;
return True;
end Strictly_Ascending;</langsyntaxhighlight>
 
If the variable Strings is of the type String_Vec.vector, one can call these two functions
as usual.
<langsyntaxhighlight Adalang="ada">Put_Line(Boolean'Image(All_Are_The_Same(Strings)) & ", " &
Boolean'Image(Strictly_Ascending(Strings)));</langsyntaxhighlight>
If Strings holds two or more strings, the result will be either of TRUE, FALSE, or FALSE, TRUE, or FALSE, FALSE, indicating all strings are the same, or they are strictly ascending, or neither.
 
Line 172 ⟶ 259:
 
=={{header|ALGOL 68}}==
<langsyntaxhighlight ALGOL68lang="algol68">[]STRING list1 = ("AA","BB","CC");
[]STRING list2 = ("AA","AA","AA");
[]STRING list3 = ("AA","CC","BB");
Line 184 ⟶ 271:
BOOL ok := TRUE;
FOR i TO UPB list - 1 WHILE ok DO
ok := list[i] = list[i+1]
OD;
ok
Line 193 ⟶ 280:
BOOL ok := TRUE;
FOR i TO UPB list - 1 WHILE ok DO
ok := list[i] < list[i + 1]
OD;
ok
Line 211 ⟶ 298:
print (("...is not in strict ascending order", new line))
FI
OD</langsyntaxhighlight>
{{out}}
<pre>list: AA BB CC
Line 231 ⟶ 318:
 
=={{header|ALGOL W}}==
<langsyntaxhighlight lang="algolw"> % returns true if all elements of the string array a are equal, false otherwise %
% As Algol W procedures cannot determine the bounds of an array, the bounds %
% must be specified in lo and hi %
Line 266 ⟶ 353:
end;
ordered
end ascendingOrder ;</langsyntaxhighlight>
 
=={{header|AppleScript}}==
Line 274 ⟶ 361:
 
 
<langsyntaxhighlight AppleScriptlang="applescript">-- allEqual :: [String] -> Bool
on allEqual(xs)
_and(zipWith(my _equal, xs, rest of xs))
Line 382 ⟶ 469:
end script
end if
end mReturn</langsyntaxhighlight>
 
{{Out}}
<pre>{allEqual:{false, false, true}, azSorted:{false, true, true}}</pre>
 
=={{header|Arturo}}==
 
<syntaxhighlight lang="rebol">allEqual?: function [lst] -> 1 = size unique lst
ascending?: function [lst] -> lst = sort lst
 
lists: [
["abc" "abc" "abc"]
["abc" "abd" "abc"]
["abc" "abd" "abe"]
["abc" "abe" "abd"]
]
 
loop lists 'l [
print ["list:" l]
print ["allEqual?" allEqual? l]
print ["ascending?" ascending? l "\n"]
]</syntaxhighlight>
 
{{out}}
 
<pre>list: [abc abc abc]
allEqual? true
ascending? true
list: [abc abd abc]
allEqual? false
ascending? false
list: [abc abd abe]
allEqual? false
ascending? true
list: [abc abe abd]
allEqual? false
ascending? false</pre>
 
=={{header|AWK}}==
<syntaxhighlight lang="awk">
<lang AWK>
# syntax: GAWK -f COMPARE_A_LIST_OF_STRINGS.AWK
BEGIN {
Line 416 ⟶ 539:
printf("\n%d\n%d\n",test1,test2)
}
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 439 ⟶ 562:
1
</pre>
 
=={{header|BQN}}==
If grade up matches grade down, then all elements are equal.
 
If all are not equal and the list is invariant under sorting, then it is in ascending order.
<syntaxhighlight lang="bqn">AllEq ← ⍋≡⍒
Asc ← ¬∘AllEq∧∧≡⊢
 
•Show AllEq ⟨"AA", "AA", "AA", "AA"⟩
•Show Asc ⟨"AA", "AA", "AA", "AA"⟩
 
•Show AllEq ⟨"AA", "ACB", "BB", "CC"⟩
•Show Asc ⟨"AA", "ACB", "BB", "CC"⟩</syntaxhighlight>
<syntaxhighlight lang="bqn">1
0
0
1</syntaxhighlight>
 
[https://mlochbaum.github.io/BQN/try.html#code=QWxsRXEg4oaQIOKNi+KJoeKNkgpBc2Mg4oaQIMKs4oiYQWxsRXHiiKfiiKfiiaHiiqIKCuKAolNob3cgQWxsRXEg4p+oIkFBIiwgIkFBIiwgIkFBIiwgIkFBIuKfqQrigKJTaG93IEFzYyDin6giQUEiLCAiQUEiLCAiQUEiLCAiQUEi4p+pCgrigKJTaG93IEFsbEVxIOKfqCJBQSIsICJBQ0IiLCAiQkIiLCAiQ0Mi4p+pCuKAolNob3cgQXNjIOKfqCJBQSIsICJBQ0IiLCAiQkIiLCAiQ0Mi4p+pCg== Try It!]
 
=={{header|Bracmat}}==
Line 468 ⟶ 610:
 
 
<langsyntaxhighlight Bracmatlang="bracmat"> (test1=first.~(!arg:%@?first ? (%@:~!first) ?))
& (test2=x.~(!arg:? %@?x (%@:~>!x) ?))</langsyntaxhighlight>
 
Demonstration
<langsyntaxhighlight Bracmatlang="bracmat">( ( lstA
. isiZulu
isiXhosa
Line 527 ⟶ 669:
)
)
</syntaxhighlight>
</lang>
'''Output'''
<pre>test1 lstA fails
Line 535 ⟶ 677:
test1 lstC succeeds
test2 lstC fails</pre>
 
=={{header|Bruijn}}==
{{trans|Haskell}}
 
<syntaxhighlight lang="bruijn">
:import std/String .
 
all-eq? [land? (zip-with eq? 0 (tail 0))]
 
all-gt? [land? (zip-with lt? 0 (tail 0))]
 
# --- tests ---
 
list-a "abc" : ("abc" : {}("abc"))
 
list-b "abc" : ("def" : {}("ghi"))
 
:test (all-eq? list-a) ([[1]])
:test (all-eq? list-b) ([[0]])
:test (all-gt? list-a) ([[0]])
:test (all-gt? list-b) ([[1]])
</syntaxhighlight>
 
=={{header|C}}==
<langsyntaxhighlight lang="c">#include <stdiostdbool.h>
#include <string.h>
 
static bool
int strings_are_equal(char * * strings, int nstrings)
strings_are_equal(const char **strings, size_t nstrings)
{
for (size_t i = 1; i < nstrings; i++)
int result = 1;
if (strcmp(strings[0], strings[i]) != 0)
return false;
while (result && (--nstrings > 0))
return true;
{
result = !strcmp(*strings, *(strings+nstrings));
}
 
return result;
}
 
static bool
int strings_are_in_ascending_order(char * * strings, int nstrings)
strings_are_in_ascending_order(const char **strings, size_t nstrings)
{
for (size_t i = 1; i < nstrings; i++)
int result = 1;
if (strcmp(strings[i - 1], strings[i]) >= 0)
int k = 0;
return false;
return true;
while (result && (++k < nstrings))
}</syntaxhighlight>
{
result = (0 >= strcmp(*(strings+k-1), *(strings+k)));
}
 
return result;
}</lang>
 
=={{header|C sharp|C#}}==
{{works with|C sharp|7}}
<langsyntaxhighlight lang="csharp">public static (bool lexicallyEqual, bool strictlyAscending) CompareAListOfStrings(List<string> strings) =>
strings.Count < 2 ? (true, true) :
(
strings.Distinct().Count() < 2,
Enumerable.Range(1, strings.Count - 1).All(i => string.Compare(strings[i-1], strings[i]) < 0)
);</langsyntaxhighlight>
 
=={{header|C++}}==
Line 579 ⟶ 736:
 
{{works with|C++|11}}
<langsyntaxhighlight lang="cpp">#include <algorithm>
#include <string>
 
// Bug: calling operator++ on an empty collection invokes undefined behavior.
std::all_of( ++(strings.begin()), strings.end(),
[&](std::string a){ return a == strings.front(); } ) // All equal
 
std::is_sorted( strings.begin(), strings.end(),
[](std::string a, std::string b){ return !(b < a); }) ) // Strictly ascending</langsyntaxhighlight>
 
=={{header|Clojure}}==
Used similar approach as the Python solution
 
<langsyntaxhighlight lang="clojure">
 
;; Checks if all items in strings list are equal (returns true if list is empty)
Line 599 ⟶ 757:
(every? (fn [[a nexta]] (<= (compare a nexta) 0)) (map vector strings (rest strings))))
 
</syntaxhighlight>
</lang>
 
=={{header|COBOL}}==
{{works with|GnuCOBOL}}
<langsyntaxhighlight lang="cobol"> identification division.
program-id. CompareLists.
 
Line 662 ⟶ 820:
end-if
display " "
.</langsyntaxhighlight>
{{out}}
<pre>list:
Line 691 ⟶ 849:
 
=={{header|Common Lisp}}==
<syntaxhighlight lang="lisp">
<lang Lisp>
(defun strings-equal-p (strings)
(null (remove (first strings) (rest strings) :test #'string=)))
Line 699 ⟶ 857:
for string2 in (rest strings)
always (string-lessp string1 string2)))
</syntaxhighlight>
</lang>
 
=={{header|D}}==
<langsyntaxhighlight lang="d">void main() {
import std.stdio, std.algorithm, std.range, std.string;
 
Line 711 ⟶ 869:
writeln;
}
}</langsyntaxhighlight>
{{out}}
<pre>["AA", "AA", "AA", "AA"]
Line 721 ⟶ 879:
true
</pre>
=={{header|Delphi}}==
{{libheader| System.SysUtils}}
{{Trans|Go}}
<syntaxhighlight lang="delphi">
program Compare_a_list_of_strings;
 
{$APPTYPE CONSOLE}
 
uses
System.SysUtils;
 
type
// generic alias for use helper. The "TArray<string>" will be work too
TListString = TArray<string>;
 
TListStringHelper = record helper for TListString
function AllEqual: boolean;
function AllLessThan: boolean;
function ToString: string;
end;
 
{ TListStringHelper }
 
function TListStringHelper.AllEqual: boolean;
begin
Result := True;
if Length(self) < 2 then
exit;
 
var first := self[0];
for var i := 1 to High(self) do
if self[i] <> first then
exit(False);
end;
 
function TListStringHelper.AllLessThan: boolean;
begin
Result := True;
if Length(self) < 2 then
exit;
 
var last := self[0];
for var i := 1 to High(self) do
begin
if not (last < self[i]) then
exit(False);
last := self[i];
end;
end;
 
function TListStringHelper.ToString: string;
begin
Result := '[';
Result := Result + string.join(', ', self);
Result := Result + ']';
end;
 
var
lists: TArray<TArray<string>>;
 
begin
lists := [['a'], ['a', 'a'], ['a', 'b']];
 
for var list in lists do
begin
writeln(list.ToString);
writeln('Is AllEqual: ', list.AllEqual);
writeln('Is AllLessThan: ', list.AllLessThan, #10);
end;
 
readln;
end.</syntaxhighlight>
{{out}}
<pre>[a]
Is AllEqual: TRUE
Is AllLessThan: TRUE
 
[a, a]
Is AllEqual: TRUE
Is AllLessThan: FALSE
 
[a, b]
Is AllEqual: FALSE
Is AllLessThan: TRUE</pre>
 
=={{header|Dyalect}}==
 
<langsyntaxhighlight Dyalectlang="dyalect">func isSorted(xs) {
var prev
for x in xs {
Line 744 ⟶ 986:
}
true
}</langsyntaxhighlight>
 
=={{header|EasyLang}}==
{{trans|AWK}}
 
<syntaxhighlight lang=easylang>
proc test s$[] . .
ident = 1
ascend = 1
for i = 2 to len s$[]
h = strcmp s$[i] s$[i - 1]
if h <> 0
ident = 0
.
if h <= 0
ascend = 0
.
.
print s$[]
if ident = 1
print "all equal"
.
if ascend = 1
print "ascending"
.
print ""
.
test [ "AA" "BB" "CC" ]
test [ "AA" "AA" "AA" ]
test [ "AA" "CC" "BB" ]
test [ "AA" "ACB" "BB" "CC" ]
test [ "single_element" ]
</syntaxhighlight>
 
=={{header|Elena}}==
ELENA 56.0x :
<langsyntaxhighlight lang="elena">import system'collections;
import system'routines;
import extensions;
Line 755 ⟶ 1,029:
{
isEqual()
= nil == self.seekEach(self.FirstMember, (n,m => m.equal:n.Inverted != n));
isAscending()
Line 764 ⟶ 1,038:
later.next();
^ nil == former.zipBy(later, (prev,next => next <= prev )).seekEach::(b => b)
}
}
Line 778 ⟶ 1,052:
public program()
{
testCases.forEach::(list)
{
console.printLine(list.asEnumerable()," all equal - ",list.isEqual());
Line 785 ⟶ 1,059:
console.readChar()
}</langsyntaxhighlight>
{{out}}
<pre>
Line 791 ⟶ 1,065:
AA,BB,CC ascending - true
AA,AA,AA all equal - true
AA,AA,AA ascending - falsetrue
AA,CC,BB all equal - false
AA,CC,BB ascending - false
Line 801 ⟶ 1,075:
 
=={{header|Elixir}}==
<langsyntaxhighlight lang="elixir">defmodule RC do
def compare_strings(strings) do
{length(Enum.uniq(strings))<=1, strict_ascending(strings)}
Line 814 ⟶ 1,088:
Enum.each(lists, fn list ->
IO.puts "#{inspect RC.compare_strings(list)}\t<= #{inspect list} "
end)</langsyntaxhighlight>
 
{{out}}
Line 828 ⟶ 1,102:
{{trans|Haskell}}
 
<langsyntaxhighlight lang="erlang">
-module(compare_strings).
 
Line 841 ⟶ 1,115:
all_fulfill(Fun,Strings) ->
lists:all(fun(X) -> X end,lists:zipwith(Fun, lists:droplast(Strings), tl(Strings)) ).
</syntaxhighlight>
</lang>
 
=={{header|F_Sharp|F#}}==
<langsyntaxhighlight lang="fsharp">let allEqual strings = Seq.isEmpty strings || Seq.forall (fun x -> x = Seq.head strings) (Seq.tail strings)
let ascending strings = Seq.isEmpty strings || Seq.forall2 (fun x y -> x < y) strings (Seq.tail strings)</langsyntaxhighlight>
<p>Actually <code>allEqual</code> is a shortcut and <code>ascending</code> is a general pattern. We can make a function
out of it which constructs a new function from a comparision function</p>
<langsyntaxhighlight lang="fsharp">let (!) f s = Seq.isEmpty s || Seq.forall2 f s (Seq.tail s)</langsyntaxhighlight>
<p>and define the 2 task functions that way</p>
<langsyntaxhighlight lang="fsharp">let allEqual = !(=)
let ascending = !(<)</langsyntaxhighlight>
<p>getting something similar as the builtin in Raku</p>
 
=={{header|Factor}}==
Assuming the list is on top of the data stack, testing for lexical equality:
<langsyntaxhighlight lang="factor">USE: grouping
all-equal?</langsyntaxhighlight>
Testing for ascending order:
<langsyntaxhighlight lang="factor">USING: grouping math.order ;
[ before? ] monotonic?</langsyntaxhighlight>
 
=={{header|Forth}}==
Line 868 ⟶ 1,142:
Raw Forth is a very low level language and has no Native lists so we have to build from scratch.
Remarkably by concatenating these low level operations and using the simple Forth parser we can build the linked lists of strings and the list operators quite simply. The operators and lists that we create become extensions to the language.
<langsyntaxhighlight lang="forth">\ linked list of strings creators
: ," ( -- ) [CHAR] " WORD c@ 1+ ALLOT ; \ Parse input stream until " and write into next available memory
: [[ ( -- ) 0 C, ; \ begin a list. write a 0 into next memory byte (null string)
Line 911 ⟶ 1,185:
create strings [[ ," ENTRY 4" ," ENTRY 3" ," ENTRY 2" ," ENTRY 1" ]]
create strings2 [[ ," the same" ," the same" ," the same" ]]
create strings3 [[ ," AAA" ," BBB" ," CCC" ," DDD" ]] </langsyntaxhighlight>
 
Test at the Forth console
Line 929 ⟶ 1,203:
Application code is hard to write and hard to read when low-level code is mixed in with application code.
It is better to hide low-level code in general-purpose code-libraries so that the application code can be simple.
Here is my solution using LIST.4TH from my novice-package: httphttps://www.forthforth2020.org/beginners-to-forth/a-novice.html-package
<langsyntaxhighlight lang="forth">
: test-equality ( string node -- new-string bad? )
over count \ -- string node adr cnt
Line 944 ⟶ 1,218:
seq .line @ seq 2nd 'test find-node
nip 0= ;
</syntaxhighlight>
</lang>
Here is a test of the above code:
{{out}}
Line 968 ⟶ 1,242:
On the other hand a function such as ALLINORDER would show the sound of one hand clapping. It would also reveal the order in which comparisons were made, and whether the loop would quit on the first failure or blockheadedly slog on through the lot regardless. Alas, on these questions the documentation for ALL is suspiciously silent.
 
<syntaxhighlight lang="fortran">
<lang Fortran>
INTEGER MANY,LONG
PARAMETER (LONG = 6,MANY = 4) !Adjust to suit.
Line 987 ⟶ 1,261:
END IF
END
</langsyntaxhighlight>
 
And yes, if MANY is set to one and the extra texts are commented out, the results are both true, and ungrammatical statements are made. Honest. Possibly, another special function, as in <code>COUNT(STRINGS(1:MANY - 1) .LT. STRINGS(2:MANY)))</code> would involve less one-hand-clapping when there are no comparisons to make, but the production of a report that would use it is not in the specification.
Line 993 ⟶ 1,267:
===F2003-F2008===
F2008 standard ([ISO 2010], 4.4.3) defines the character variable of the character type as a set of values composed of character strings and a character string is a sequence of characters, numbered from left to right 1, 2, 3, ... up to the number of characters in the string. The number of characters in the string is called the length of the string. The length is a type parameter; its kind is processor dependent and its value is greater than or equal to zero. I.e in declaration
<syntaxhighlight lang="fortran">
<lang Fortran>
character (len=12) :: surname
</syntaxhighlight>
</lang>
keyword len is NOT a size of array, it is an intrinsic parameter of character type, and character type is in fortran a [[first-class type]]: they can be assigned as objects or passed as parameters to a subroutine.
 
In summary, the character data type in Fortran is a real, first class data type. Fortran character strings are not hacked-up arrays!
<syntaxhighlight lang="fortran">
<lang Fortran>
program compare_char_list
implicit none
Line 1,017 ⟶ 1,291:
end if
end program compare_char_list
</syntaxhighlight>
</lang>
 
=={{header|FreeBASIC}}==
<langsyntaxhighlight lang="freebasic">
' FB 1.05.0 Win64
 
Line 1,040 ⟶ 1,314:
Return True
End Function
</syntaxhighlight>
</lang>
 
=={{header|Fōrmulæ}}==
 
In [{{FormulaeEntry|page=https://wiki.formulae.org/?script=examples/Compare_a_list_of_strings this] page you can see the solution of this task.}}
 
Fōrmulæ programs are not textual, visualization/edition of programs is done showing/manipulating structures but not text ([http://wiki.formulae.org/Editing_F%C5%8Drmul%C3%A6_expressions more info]). Moreover, there can be multiple visual representations of the same program. Even though it is possible to have textual representation &mdash;i.e. XML, JSON&mdash; they are intended for transportation effects more than visualization and edition.
 
 
The option to show Fōrmulæ programs and their results is showing images. Unfortunately images cannot be uploaded in Rosetta Code.
=={{header|FutureBasic}}==
<syntaxhighlight lang="futurebasic">
local fn ListObjectsAreIdentical( array as CFArrayRef ) as BOOL
BOOL result = NO
CFSetRef set = fn SetWithArray( array )
result = ( fn SetCount( set ) <= 1 )
end fn = result
 
local fn ListIsInLexicalOrder( array as CFArrayRef ) as BOOL
BOOL result = NO
CFArrayRef sortedArray = fn ArraySortedArrayUsingSelector( array, @"compare:" )
result = fn ArrayIsEqual( array, sortedArray )
end fn = result
 
void local fn ListTest
long i
CFArrayRef listA = @[@"aaa", @"aaa", @"aaa", @"aaa"]
CFArrayRef listB = @[@"aaa", @"aab", @"aba", @"baa"]
CFArrayRef listC = @[@"caa", @"aab", @"aca", @"abc"]
CFArrayRef lists = @[listA, listB, listC]
for i = 0 to 2
CFArrayRef temp = lists[i]
printf @"Input array elements: %@ %@ %@ %@", temp[0], temp[1], temp[2], temp[3]
if ( fn ListObjectsAreIdentical( temp ) )
printf @"List elements are lexically equal."
else
printf @"List elements not lexically equal."
end if
if ( fn ListIsInLexicalOrder( temp ) == YES )
printf @"List elements are in ascending order."
else
printf @"List elements not in ascending order."
end if
CFArrayRef sorted = fn ArraySortedArrayUsingSelector( temp, @"compare:" )
printf @"List elements sorted in ascending order: %@ %@ %@ %@", sorted[0], sorted[1], sorted[2], sorted[3]
print
next
end fn
 
fn ListTest
 
HandleEvents
</syntaxhighlight>
{{output}}
<pre>
Input array elements: aaa aaa aaa aaa
List elements are lexically equal.
List elements are in ascending order.
List elements sorted in ascending order: aaa aaa aaa aaa
 
Input array elements: aaa aab aba baa
List elements not lexically equal.
List elements are in ascending order.
List elements sorted in ascending order: aaa aab aba baa
 
Input array elements: caa aab aca abc
List elements not lexically equal.
List elements not in ascending order.
List elements sorted in ascending order: aab abc aca caa
</pre>
 
=={{header|Go}}==
<langsyntaxhighlight lang="go">package cmp
 
func AllEqual(strings []string) bool {
for _, s := range strings {
if len(strings) < 2 {
if s != strings[0] {
return true
}
 
first := strings[0]
for _, s := range strings[1:] {
if s != first {
return false
}
Line 1,068 ⟶ 1,400:
 
func AllLessThan(strings []string) bool {
iffor i := 1; i < len(strings); < 2i++ {
if !(strings[i - 1] < s) {
return true
}
 
last := strings[0]
for _, s := range strings[1:] {
if !(last < s) {
return false
}
last = s
}
return true
}</langsyntaxhighlight>
See [[Compare_a_list_of_strings/GoTests]] for validation tests.
 
Line 1,086 ⟶ 1,412:
 
=={{header|Gosu}}==
<langsyntaxhighlight lang="gosu">var list = {"a", "b", "c", "d"}
 
var isHomogeneous = list.toSet().Count < 2
var isOrderedSet = list.toSet().order().toList() == list</langsyntaxhighlight>
 
=={{header|Haskell}}==
<langsyntaxhighlight lang="haskell">allEqual :: Eq a => [a] -> Bool
allEqual xs = and $ zipWith (==) xs (tail xs)
allIncr :: Ord a => [a] -> Bool
allIncr xs = and $ zipWith (<) xs (tail xs)</langsyntaxhighlight>
 
 
Alternatively, using folds:
 
<langsyntaxhighlight lang="haskell">allEqual
:: Eq a
=> [a] -> Bool
Line 1,111 ⟶ 1,437:
=> [a] -> Bool
allIncreasing [] = True
allIncreasing (h:t) = fst $ foldl (\(a, x) y -> (a && x < y, y)) (True, h) t</langsyntaxhighlight>
 
or seeking earlier exit (from longer lists) with '''until''', but in fact, perhaps due to lazy execution, the zipWith at the top performs best.
 
<langsyntaxhighlight lang="haskell">allEq
:: Eq a
=> [a] -> Bool
Line 1,135 ⟶ 1,461:
(\(x, xs) -> null xs || x >= head xs)
(\(_, x:xs) -> (x, xs))
(h, t)</langsyntaxhighlight>
 
=={{header|Icon}} and {{header|Unicon}}==
Icon and Unicon expressions either succeed and return a value (which may be &null) or fail.
 
<langsyntaxhighlight lang="unicon">#
# list-compare.icn
#
Line 1,181 ⟶ 1,507:
}
return
end</langsyntaxhighlight>
 
{{out}}
Line 1,193 ⟶ 1,519:
=={{header|J}}==
 
'''Solution''' (''equality test''):<langsyntaxhighlight lang="j"> allEq =: 1 = +/@~: NB. or 1 = #@:~. or -: 1&|. or }.-:}:</langsyntaxhighlight>
'''Solution''' (''order test''):<langsyntaxhighlight lang="j"> asc =: /: -: i.@# NB. or -: (/:~) etc.</langsyntaxhighlight>
'''Notes''': <tt>asc</tt> indicates whether <tt>y</tt> is monotonically increasing, but not necessarily strictly monotonically increasing (in other words, it allows equal elements if they are adjacent to each other).
 
=={{header|Java}}==
This is a fairly basic procedure in Java, using <kbd>for-loop</kbd>s, <code>String.equals</code>, and <code>String.compareTo</code>.
<syntaxhighlight lang="java">
boolean allEqual(String[] strings) {
String stringA = strings[0];
for (String string : strings) {
if (!string.equals(stringA))
return false;
}
return true;
}
</syntaxhighlight>
<syntaxhighlight lang="java">
boolean isAscending(String[] strings) {
String previous = strings[0];
int index = 0;
for (String string : strings) {
if (index++ == 0)
continue;
if (string.compareTo(previous) < 0)
return false;
previous = string;
}
return true;
}
</syntaxhighlight>
<br />
Alternately,
{{works with|Java|8}}
<langsyntaxhighlight lang="java5">import java.util.Arrays;
 
public class CompareListOfStrings {
Line 1,206 ⟶ 1,559:
String[][] arr = {{"AA", "AA", "AA", "AA"}, {"AA", "ACB", "BB", "CC"}};
for (String[] a : arr) {
System.out.printfprintln("%s%n%s%n%s%n", Arrays.toString(a),);
System.out.println(Arrays.stream(a).distinct().count() < a.length,2);
System.out.println(Arrays.equals(Arrays.stream(a).distinct().sorted().toArray(), a));
}
}
}</langsyntaxhighlight>
{{out}}
<pre>[AA, AA, AA, AA]
Line 1,223 ⟶ 1,576:
===ES5===
====Iterative====
<langsyntaxhighlight JavaScriptlang="javascript">function allEqual(a) {
var out = true, i = 0;
while (++i<a.length) {
Line 1,246 ⟶ 1,599:
console.log(azSorted(empty)); // true
console.log(azSorted(single)); // true
</syntaxhighlight>
</lang>
 
===ES6===
Line 1,252 ⟶ 1,605:
 
Using a generic zipWith, and functionally composed predicates:
<langsyntaxhighlight JavaScriptlang="javascript">(() => {
'use strict';
 
Line 1,302 ⟶ 1,655:
};
 
})();</langsyntaxhighlight>
 
{{Out}}
<syntaxhighlight lang="javascript">{
<lang JavaScript>{
"allEqual": [
false,
Line 1,316 ⟶ 1,669:
true
]
}</langsyntaxhighlight>
 
=={{header|jq}}==
Line 1,323 ⟶ 1,676:
For both the following functions, the input is assumed to be a (possibly empty) array of strings.
In both cases also, the implementations are fast but could be improved at the expense of complexity.
<langsyntaxhighlight lang="jq"># Are the strings all equal?
def lexically_equal:
. as $in
Line 1,333 ⟶ 1,686:
. as $in
| reduce range(0;length-1) as $i
(true; if . then $in[$i] < $in[$i + 1] else false end);</langsyntaxhighlight>
'''Examples''':
<langsyntaxhighlight lang="jq">[] | lexically_equal #=> true</langsyntaxhighlight>
<langsyntaxhighlight lang="jq">["a", "ab"] | lexically_ascending #=> true</langsyntaxhighlight>
 
=={{header|Jsish}}==
Code from Javascript, ES5.
 
<langsyntaxhighlight lang="javascript">/* Compare list of strings, in Jsish */
function allEqual(a) {
var out = true, i = 0;
Line 1,360 ⟶ 1,713:
 
if (allAscending(strings)) puts("strings array in strict ascending order");
else puts("strings array not in strict ascending order");</langsyntaxhighlight>
 
{{out}}
Line 1,368 ⟶ 1,721:
{{works with|Julia|0.6}}
 
<langsyntaxhighlight lang="julia">allequal(arr::AbstractArray) = isempty(arr) || all(x -> x == first(arr), arr)
 
test = [["RC", "RC", "RC"], ["RC", "RC", "Rc"], ["RA", "RB", "RC"],
Line 1,377 ⟶ 1,730:
println("The elements are $("not " ^ !allequal(v))all equal.")
println("The elements are $("not " ^ !issorted(v))strictly increasing.")
end</langsyntaxhighlight>
 
{{out}}
Line 1,409 ⟶ 1,762:
 
=={{header|Klong}}==
<syntaxhighlight lang="k">
<lang K>
{:[2>#x;1;&/=:'x]}:(["test" "test" "test"])
1
{:[2>#x;1;&/<:'x]}:(["bar" "baz" "foo"])
1
</syntaxhighlight>
</lang>
 
=={{header|Kotlin}}==
<langsyntaxhighlight lang="scala">// version 1.0.6
 
fun areEqual(strings: Array<String>): Boolean {
if (strings.size < 2) return true
return (1 until strings.size).noneall { strings[it] !== strings[it - 1] }
}
 
fun areAscending(strings: Array<String>): Boolean {
if (strings.size < 2) return true
return (1 until strings.size).noneall { strings[it] <=> strings[it - 1] }
}
 
Line 1,436 ⟶ 1,789:
else if (areAscending(args)) println("They are in strictly ascending order")
else println("They are neither equal nor in ascending order")
}</langsyntaxhighlight>
Sample input/output:
{{out}}
Line 1,445 ⟶ 1,798:
 
=={{header|Lambdatalk}}==
<langsyntaxhighlight lang="scheme">
{def allsame
{def allsame.r
Line 1,488 ⟶ 1,841:
} -> true false false true true
 
</syntaxhighlight>
</lang>
 
=={{header|Lua}}==
<langsyntaxhighlight lang="lua">function identical(t_str)
_, fst = next(t_str)
if fst then
Line 1,530 ⟶ 1,883:
check("AA,CC,BB")
check("AA,ACB,BB,CC")
check("single_element")</langsyntaxhighlight>
{{out}}
<pre>ayu dab dog gar panda tui yak: not identical and ascending.
Line 1,543 ⟶ 1,896:
 
=={{header|M2000 Interpreter}}==
<syntaxhighlight lang="m2000 interpreter">
<lang M2000 Interpreter>
Module CheckIt {
Function Equal(Strings){
Line 1,583 ⟶ 1,936:
}
Checkit
</syntaxhighlight>
</lang>
 
=={{header|Maple}}==
<langsyntaxhighlight Maplelang="maple">lexEqual := proc(lst)
local i:
for i from 2 to numelems(lst) do
Line 1,602 ⟶ 1,955:
tst := ["abc","abc","abc","abc","abc"]:
lexEqual(tst):
lexAscending(tst):</langsyntaxhighlight>
{{Out|Examples}}
<pre>true
false</pre>
 
=={{header|MathematicaMathcad}}==
Mathcad is a non-text-based programming environment. The expressions below are an approximations of the way that they are entered (and) displayed on a Mathcad worksheet. The worksheet is available at xxx_tbd_xxx
<lang Mathematica>data1 = {"aaa", "aaa", "aab"};
 
This particular version of "Compare a list of strings" was created in Mathcad Prime Express 7.0, a free version of Mathcad Prime 7.0 with restrictions (such as no programming or symbolics). All Mathcad numbers are complex doubles. There is a recursion depth limit of about 4,500. Strings are a distinct data and are not conceptually a list of integers.
 
<syntaxhighlight lang="mathcad">-- define list of list of strings (nested vector of vectors of strings)
-- Mathcad vectors are single column arrays.
-- The following notation is for convenience in writing arrays in text form.
-- Mathcad array input is normally via Mathcad's array operator or via one of the
-- array-builder functions, such as stack or augment.
-- "," between vector elements indicates a new row.
-- " " between vector elements indicates a new column.
 
list:=["AA","AA","AA"],["AA","BB","CC"],["AA","CC","BB"],["CC","BB","AA"],["AA","ACB","BB","CC"],["AA"]]
 
-- define functions head and rest that return the first value in a list (vector)
-- and the list excluding the first element, respectively.
 
head(v):=if(IsArray(v),v[0,v)
rest(v):=if(rows(v)>1,submatrix(v,1,rows(v)-1,0,0),0)
 
-- define a function oprel that iterates through a list (vector) applying a comparison operator op to each pair of elements at the top of the list.
-- Returns immediately with false (0) if a comparison fails.
 
oprel(op,lst,val):=if(op(val,head(lst)),if(rows(lst)>1,oprel(op,rest(lst),head(lst)),1),0)
 
oprel(op,lst):=if(rows(lst)>1,oprel(op,rest(lst),head(lst)),1)
 
-- define a set of boolean comparison functions
-- transpose represents Mathcad's transpose operator
-- vectorize represents Mathcad's vectorize operator
 
eq(a,b):=a=b (transpose(vectorize(oprel,list))) = [1 0 0 0 0 1] -- equal
lt(a,b):=a<b (transpose(vectorize(oprel,list))) = [0 1 0 0 1 1] -- ascending
 
-- oprel, eq and lt also work with numeric values
 
list:=[11,11,11],[11,22,33],[11,33,22],[33,22,11],[11,132,22,33],[11]]
</syntaxhighlight>
 
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<syntaxhighlight lang="mathematica">data1 = {"aaa", "aaa", "aab"};
Apply[Equal, data]
OrderedQ[data]</langsyntaxhighlight>
{{out}}
<pre>False
True</pre>
 
 
=={{header|MATLAB}} / {{header|Octave}}==
Only the first task is implemented.
<syntaxhighlight lang="matlab">alist = {'aa', 'aa', 'aa'}
<lang Matlab>
all(strcmp(alist,alist{1}))</syntaxhighlight>
alist = {'aa', 'aa', 'aa'}
all(strcmp(alist,alist{1}))
 
</lang>
 
=={{header|Nanoquery}}==
<langsyntaxhighlight Nanoquerylang="nanoquery">// a function to test if a list of strings are equal
def stringsEqual(stringList)
// if the list is empty, return true
Line 1,661 ⟶ 2,050:
// return whether the string were less than each other or not
return lessThan
end</langsyntaxhighlight>
 
=={{header|NetRexx}}==
<langsyntaxhighlight NetRexxlang="netrexx">/* NetRexx */
options replace format comments java crossref symbols nobinary
 
Line 1,710 ⟶ 2,099:
return
 
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 1,726 ⟶ 2,115:
elements are in ascending order
</pre>
 
=={{header|Nim}}==
 
This is the obvious (and more efficient way) to compare strings in Nim:
 
<syntaxhighlight lang="nim">
func allEqual(s: openArray[string]): bool =
 
for i in 1..s.high:
if s[i] != s[0]:
return false
result = true
 
func ascending(s: openArray[string]): bool =
 
for i in 1..s.high:
if s[i] <= s[i - 1]:
return false
result = true
 
doAssert allEqual(["abc", "abc", "abc"])
doAssert not allEqual(["abc", "abd", "abc"])
 
doAssert ascending(["abc", "abd", "abe"])
doAssert not ascending(["abc", "abe", "abd"])
 
doAssert allEqual(["abc"])
doAssert ascending(["abc"])</syntaxhighlight>
 
For “allEqual”, there is another simple way using template “allIt” from standard module “sequtils”:
 
<syntaxhighlight lang="nim">import sequtils
 
func allEqual(s: openArray[string]): bool =
allIt(s, it == s[0])
 
doAssert allEqual(["abc", "abc", "abc"])
doAssert not allEqual(["abc", "abd", "abc"])
doAssert allEqual(["abc"])</syntaxhighlight>
 
There are other less obvious and less efficient ways, using hash sets, sorting or “map” and “zip”.
 
=={{header|OCaml}}==
<syntaxhighlight lang="ocaml">
<lang Ocaml>
open List;;
 
Line 1,758 ⟶ 2,188:
 
List.iter test [lasc;leq;lnoasc];;
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 1,783 ⟶ 2,213:
=={{header|Oforth}}==
 
<langsyntaxhighlight lang="oforth">: lexEqual asSet size 1 <= ;
: lexCmp(l) l l right( l size 1- ) zipWith(#<) and ;</langsyntaxhighlight>
 
=={{header|ooRexx}}==
<langsyntaxhighlight lang="oorexx">/* REXX ---------------------------------------------------------------
* 28.06.2014 Walter Pachl
*--------------------------------------------------------------------*/
Line 1,818 ⟶ 2,248:
Say 'List' name': neither equal nor in increasing order'
End
Return</langsyntaxhighlight>
{{out}}
<pre>List ABC: elements are in increasing order
Line 1,826 ⟶ 2,256:
=={{header|PARI/GP}}==
Easiest is to use <code>Set()</code>:
<langsyntaxhighlight lang="parigp">allEqual(strings)=#Set(strings)<2
inOrder(strings)=Set(strings)==strings</langsyntaxhighlight>
 
More efficient:
<langsyntaxhighlight lang="parigp">allEqual(strings)=for(i=2,#strings,if(strings[i]!=strings[i-1], return(0))); 1
inOrder(strings)=for(i=2,#strings,if(strings[i]>strings[i-1], return(0))); 1</langsyntaxhighlight>
 
=={{header|Perl}}==
 
<langsyntaxhighlight lang="perl">use List::Util 1.33 qw(all);
 
all { $strings[0] eq $strings[$_] } 1..$#strings # All equal
all { $strings[$_-1] lt $strings[$_] } 1..$#strings # Strictly ascending</langsyntaxhighlight>
 
Alternatively, if you can guarantee that the input strings don't contain null bytes, the equality test can be performed by a regex like this:
 
<langsyntaxhighlight lang="perl">join("\0", @strings) =~ /^ ( [^\0]*+ ) (?: \0 \1 )* $/x # All equal</langsyntaxhighlight>
 
=={{header|Phix}}==
<!--<syntaxhighlight lang="phix">(phixonline)-->
<lang Phix>function allsame(sequence s)
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
for i=2 to length(s) do
<span style="color: #008080;">function</span> <span style="color: #000000;">allsame</span><span style="color: #0000FF;">(</span><span style="color: #004080;">sequence</span> <span style="color: #000000;">s</span><span style="color: #0000FF;">)</span>
if s[i]!=s[1] then return 0 end if
<span style="color: #008080;">for</span> <span style="color: #000000;">i</span><span style="color: #0000FF;">=</span><span style="color: #000000;">2</span> <span style="color: #008080;">to</span> <span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">s</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">do</span>
end for
<span style="color: #008080;">if</span> <span style="color: #000000;">s</span><span style="color: #0000FF;">[</span><span style="color: #000000;">i</span><span style="color: #0000FF;">]!=</span><span style="color: #000000;">s</span><span style="color: #0000FF;">[</span><span style="color: #000000;">1</span><span style="color: #0000FF;">]</span> <span style="color: #008080;">then</span> <span style="color: #008080;">return</span> <span style="color: #004600;">false</span> <span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
return 1
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
end function
<span style="color: #008080;">return</span> <span style="color: #004600;">true</span>
 
<span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
function strict_order(sequence s)
for i=2 to length(s) do
<span style="color: #008080;">function</span> <span style="color: #000000;">strict_order</span><span style="color: #0000FF;">(</span><span style="color: #004080;">sequence</span> <span style="color: #000000;">s</span><span style="color: #0000FF;">)</span>
if s[i]<=s[i-1] then return 0 end if
<span style="color: #008080;">for</span> <span style="color: #000000;">i</span><span style="color: #0000FF;">=</span><span style="color: #000000;">2</span> <span style="color: #008080;">to</span> <span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">s</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">do</span>
end for
<span style="color: #008080;">if</span> <span style="color: #000000;">s</span><span style="color: #0000FF;">[</span><span style="color: #000000;">i</span><span style="color: #0000FF;">]<=</span><span style="color: #000000;">s</span><span style="color: #0000FF;">[</span><span style="color: #000000;">i</span><span style="color: #0000FF;">-</span><span style="color: #000000;">1</span><span style="color: #0000FF;">]</span> <span style="color: #008080;">then</span> <span style="color: #008080;">return</span> <span style="color: #004600;">false</span> <span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
return 1
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
end function
<span style="color: #008080;">return</span> <span style="color: #004600;">true</span>
 
<span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
procedure test(sequence s)
?{s,allsame(s),strict_order(s)}
<span style="color: #008080;">procedure</span> <span style="color: #000000;">test</span><span style="color: #0000FF;">(</span><span style="color: #004080;">sequence</span> <span style="color: #000000;">s</span><span style="color: #0000FF;">)</span>
end procedure
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"%-22V allsame:%5t, strict_order:%5t\n"</span><span style="color: #0000FF;">,{</span><span style="color: #000000;">s</span><span style="color: #0000FF;">,</span><span style="color: #000000;">allsame</span><span style="color: #0000FF;">(</span><span style="color: #000000;">s</span><span style="color: #0000FF;">),</span><span style="color: #000000;">strict_order</span><span style="color: #0000FF;">(</span><span style="color: #000000;">s</span><span style="color: #0000FF;">)})</span>
 
<span style="color: #008080;">end</span> <span style="color: #008080;">procedure</span>
test({"AA","BB","CC"})
test({"AA","AA","AA"})
<span style="color: #000000;">test</span><span style="color: #0000FF;">({</span><span style="color: #008000;">"AA"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"BB"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"CC"</span><span style="color: #0000FF;">})</span>
test({"AA","CC","BB"})
<span style="color: #000000;">test</span><span style="color: #0000FF;">({</span><span style="color: #008000;">"AA"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"AA"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"AA"</span><span style="color: #0000FF;">})</span>
test({"AA","ACB","BB","CC"})
<span style="color: #000000;">test</span><span style="color: #0000FF;">({</span><span style="color: #008000;">"AA"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"CC"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"BB"</span><span style="color: #0000FF;">})</span>
test({"single_element"})</lang>
<span style="color: #000000;">test</span><span style="color: #0000FF;">({</span><span style="color: #008000;">"AA"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"ACB"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"BB"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"CC"</span><span style="color: #0000FF;">})</span>
<span style="color: #000000;">test</span><span style="color: #0000FF;">({</span><span style="color: #008000;">"single_element"</span><span style="color: #0000FF;">})</span>
<!--</syntaxhighlight>-->
{{out}}
<pre>
{{"AA","BB","CC"} allsame:false,0,1} strict_order: true
{{"AA","AA","AA"} allsame: true,1,0} strict_order:false
{{"AA","CC","BB"} allsame:false,0,0} strict_order:false
{{"AA","ACB","BB","CC"} allsame:false,0,1} strict_order: true
{{"single_element"} allsame: true,1,1} strict_order: true
</pre>
 
=={{header|Phixmonti}}==
<langsyntaxhighlight Phixmontilang="phixmonti">include ..\Utilitys.pmt
 
( "alpha" "beta" "gamma" "delta" "epsilon" "zeta"
Line 1,888 ⟶ 2,321:
 
dup len swap 1 get rot repeat == /# put 0 (false) in the pile, indicating that they are not repeated strings #/
</syntaxhighlight>
</lang>
 
=={{header|Picat}}==
<syntaxhighlight lang="picat">main =>
Lists = [["AA","BB","CC"],
["AA","AA","AA"],
["AA","CC","BB"],
["AA","ACB","BB","CC"],
["single_element"],
[]],
foreach(L in Lists)
Same = all_same(L).cond(true,false),
Sorted = sorted(L).cond(true,false),
printf("%-18w all_same:%-5w sorted:%-5w\n",L,Same,Sorted)
end.
 
all_same([]).
all_same([_]).
all_same([A,B|Rest]) :-
A == B,
all_same([B|Rest]).</syntaxhighlight>
 
{{out}}
<pre>[AA,BB,CC] all_same:false sorted:true
[AA,AA,AA] all_same:true sorted:true
[AA,CC,BB] all_same:false sorted:false
[AA,ACB,BB,CC] all_same:false sorted:true
[single_element] all_same:true sorted:true
[] all_same:true sorted:true </pre>
 
=={{header|PicoLisp}}==
PicoLisp has the native operators =, > and < these can take an infinite number of arguments and are also able to compare Transient symbols (the Strings of PicoLisp).
<langsyntaxhighlight PicoLisplang="picolisp">(= "AA" "AA" "AA")
-> T
(= "AA" "AA" "Aa")
Line 1,903 ⟶ 2,364:
-> T
(> "A" "B" "Z" "C")
-> NIL</langsyntaxhighlight>
If you want a function which takes one list here are some straight-forward implementation:
<syntaxhighlight lang="picolisp">
<lang PicoLisp>
(de same (List)
(apply = List))
Line 1,917 ⟶ 2,378:
(same '("AA" "AA" "AA"))
-> T
</syntaxhighlight>
</lang>
This would of course also work with <= and >= without any hassle.
 
=={{header|PL/I}}==
<langsyntaxhighlight lang="pli">*process source xref attributes or(!);
/*--------------------------------------------------------------------
* 01.07.2014 Walter Pachl
Line 1,960 ⟶ 2,421:
Put Skip List(name!!': '!!txt);
End;
End;</langsyntaxhighlight>
{{out}}
<pre>ABC: elements are in increasing order
Line 1,967 ⟶ 2,428:
 
=={{header|Plain English}}==
<langsyntaxhighlight lang="plainenglish">To decide if some string things are lexically equal:
If the string things are empty, say yes.
Get a string thing from the string things.
Line 1,985 ⟶ 2,446:
If the string thing's string is less than the string thing's previous' string, say no.
Put the string thing's next into the string thing.
Repeat.</langsyntaxhighlight>
 
=={{header|PowerShell}}==
{{works with|PowerShell|4.0}}
<syntaxhighlight lang="powershell">
<lang PowerShell>
function IsAscending ( [string[]]$Array ) { ( 0..( $Array.Count - 2 ) ).Where{ $Array[$_] -le $Array[$_+1] }.Count -eq $Array.Count - 1 }
function IsEqual ( [string[]]$Array ) { ( 0..( $Array.Count - 2 ) ).Where{ $Array[$_] -eq $Array[$_+1] }.Count -eq $Array.Count - 1 }
Line 2,000 ⟶ 2,461:
IsEqual 'A', 'C', 'B', 'C'
IsEqual 'A', 'A', 'A', 'A'
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 2,013 ⟶ 2,474:
 
=={{header|Prolog}}==
<langsyntaxhighlight Prologlang="prolog">los(["AA","BB","CC"]).
los(["AA","AA","AA"]).
los(["AA","CC","BB"]).
Line 2,033 ⟶ 2,494:
nl.
 
test :- forall(los(List), test_list(List)).</langsyntaxhighlight>
{{out}}
<pre>
Line 2,061 ⟶ 2,522:
 
=={{header|PureBasic}}==
<langsyntaxhighlight lang="purebasic">EnableExplicit
DataSection
Data.s ~"AA\tAA\tAA\nAA\tBB\tCC\nAA\tCC\tBB\nAA\tACB\tBB\tCC\nsingel_element"
Line 2,098 ⟶ 2,559:
PrintN("")
Next
Input()</langsyntaxhighlight>
{{out}}
<pre>List : AA AA AA
Line 2,123 ⟶ 2,584:
A useful pattern is that when you need some function of an item in a list with its next item over possibly all items in the list then <code>f(a, nexta) for a, nexta in zip(alist, alist[1:]))</code> works nicely.
(Especially if an index is not needed elsewhere in the algorithm).
<langsyntaxhighlight lang="python">all(a == nexta for a, nexta in zip(strings, strings[1:])) # All equal
all(a < nexta for a, nexta in zip(strings, strings[1:])) # Strictly ascending
 
len(set(strings)) == 1 # Concise all equal
sorted(strings, reverse=True) == strings # Concise (but not particularly efficient) ascending
</syntaxhighlight>
</lang>
 
 
Line 2,135 ⟶ 2,596:
and, if we wish, pass functional forms of standard operators to either of them:
 
<langsyntaxhighlight lang="python">from operator import (eq, lt)
 
 
Line 2,152 ⟶ 2,613:
 
all(map(lt, az, az[1:]))
)</langsyntaxhighlight>
{{Out}}
<pre>True False True</pre>
 
=={{header|RQuackery}}==
 
Idiomatically the strings would be stored in a nest which need not be named. The words <code>allthesame</code> and <code>allinorder</code> both take a nest of strings from the stack and return a boolean.
Let's start with a function that splits a vector into
sub-vectors; it starts a new vector whenever the comparison
function yields false.
 
The word <code>$></code> compares two strings using the QACSFOT lexical ordering. (QACSFOT - Quackery Arbitrary Character Sequence For Ordered Text. It is less arbitrary than the ASCII sequence.)
<lang R>
chunks <- function (compare, xs) {
starts = which(c(T, !compare(head(xs, -1), xs[-1]), T))
lapply(seq(1,length(starts)-1),
function(i) xs[starts[i]:(starts[i+1]-1)] )
}
</lang>
 
<syntaxhighlight lang="quackery"> [ [ true swap
Testing:
dup size 1 > while
behead swap
witheach
[ over != if
[ dip not conclude ] ] ]
drop ] is allthesame ( [ --> b )
 
[ [ true swap
<lang R>
dup size 1 > while
> chunks(`<`, c(0,4,8,1,3,5,7,9))
behead swap
[[1]]
witheach
[1] 0 4 8
[ tuck $> if
[ dip not conclude ] ] ]
drop ] is allinorder ( [ --> b )</syntaxhighlight>
 
=={{header|R}}==
[[2]]
[1] 1 3 5 7 9
</lang>
 
We can test, first, whether all elements of vector `strings` are equal to the first element; and, second, whether the sorted order of the vector is equal to the original vector.
R displays the results in a very prolix manner, so let's simplify it.
 
<syntaxhighlight lang="r">
<lang R>
all(strings == strings[1])
> toString(chunks(`<`, c(0,4,8,1,3,5,7,9,-2,0,88)))
all(strings == sort(strings))
[1] "c(0, 4, 8), c(1, 3, 5, 7, 9), c(-2, 0, 88)"
</syntaxhighlight>
> toString(chunks(`==`, c(0,0,0,5,5,8)))
[1] "c(0, 0, 0), c(5, 5), 8"
</lang>
 
Testing:
Defining the required functions:
 
<syntaxhighlight lang="r">
<lang R>
manyStrings=list(
all.eq <- function(xs) 1 == length( chunks(`==`, xs))
"a",
ascending <- function(xs) 1 == length( chunks(`<`, xs))
c("a", "b", "c"),
</lang>
c("a", "c", "b"),
c("A", "A"),
c("a", "A"),
c(123, "A", "Aaron", "beryllium", "z"),
c(123, "A", "z", "Aaron", "beryllium", "z")
)
 
for (strings in manyStrings) {
Testing:
print(strings)
print(all(strings == strings[1]))
print(all(strings == sort(strings)))
}
</syntaxhighlight>
 
Result:
<syntaxhighlight>
"a"
TRUE
TRUE
"a" "b" "c"
FALSE
TRUE
"a" "c" "b"
FALSE
FALSE
"A" "A"
TRUE
TRUE
"a" "A"
FALSE
TRUE
"123" "A" "Aaron" "beryllium" "z"
FALSE
TRUE
"123" "A" "z" "Aaron" "beryllium" "z"
FALSE
FALSE
</syntaxhighlight>
 
For `NULL` input returns `TRUE` to both tests, for all missing (`NA`) input returns `NA` to first test, `TRUE` to second.
<lang R>
> all.eq(c('by'))
[1] TRUE
> all.eq(c('by','by','by'))
[1] TRUE
> all.eq(c('by','by','by','zoo'))
[1] FALSE
> ascending(c("at", "even", "once", "run", "zoo"))
[1] TRUE
> ascending(c("at", "even", "once", "run", "zoo", "we"))
[1] FALSE
> ascending(c("at", "even", "go", "go"))
[1] FALSE
> ascending(c("at"))
[1] TRUE
</lang>
 
=={{header|Racket}}==
Line 2,225 ⟶ 2,704:
 
Hence the wrapper in the code below:
<langsyntaxhighlight lang="racket">#lang racket/base
(define ((list-stringX? stringX?) strs)
(or (null? strs) (null? (cdr strs)) (apply stringX? strs)))
Line 2,246 ⟶ 2,725:
(list-string<? '("a" "a")) => #f
(list-string<? '("a" "b" "a")) => #f
(list-string<? '("a" "b" "c")) => #t))</langsyntaxhighlight>
 
=={{header|Raku}}==
(formerly Perl 6)
 
In Raku, putting square brackets around an [[wp:Infix_notation|infix]] operator turns it into a listop that effectively works as if the operator had been butput in between all of the elements of the argument list ''(or in technical terms, it [[wp:Fold_(higher-order_function)|folds/reduces]] the list using that operator, while taking into account the operator's inherent [https://design.raku.org/S03.html#Operator_precedence associativity] and identity value)'':
 
<syntaxhighlight lang="raku" perl6line>[eq] @strings # All equal
[lt] @strings # Strictly ascending</langsyntaxhighlight>
 
=={{header|Red}}==
<langsyntaxhighlight Redlang="red">Red []
 
list1: ["asdf" "Asdf" "asdf"]
Line 2,274 ⟶ 2,753:
print all-equal? list3
print sorted? list3
</syntaxhighlight>
</lang>
{{out}}
<pre>false
Line 2,286 ⟶ 2,765:
=={{header|REXX}}==
===version 1===
<langsyntaxhighlight lang="rexx">/* REXX ---------------------------------------------------------------
* 28.06.2014 Walter Pachl
*--------------------------------------------------------------------*/
Line 2,328 ⟶ 2,807:
Say 'List' value(list)': neither equal nor in increasing order'
End
Return</langsyntaxhighlight>
{{out}}
<pre>List ABC: elements are in increasing order
Line 2,340 ⟶ 2,819:
:::::::* '''parse upper arg x'''
:::::::* '''arg x'''
<langsyntaxhighlight lang="rexx">/*REXX program compares a list of (character) strings for: equality, all ascending. */
@.1= 'ayu dab dog gar panda tui yak' /*seven strings: they're all ascending.*/
@.2= 'oy oy oy oy oy oy oy oy oy oy' /* ten strings: all equal. */
Line 2,363 ⟶ 2,842:
if word(strings,k)<<=word(strings,k-1) then return 0 /*string>prev? */
end /*k*/ /* [↑] 0=false, [↓] 1=true. */
return 1 /*indicate that strings are ascending. */</langsyntaxhighlight>
{{out|output|text=&nbsp; when using the supplied lists:}}
<pre>
Line 2,389 ⟶ 2,868:
===version 3===
This REXX version is more idiomatic.
<langsyntaxhighlight lang="rexx">/*REXX program compares a list of strings for: equality, all ascending. */
@.1= 'ayu dab dog gar panda tui yak' /*seven strings: they're all ascending.*/
@.2= 'oy oy oy oy oy oy oy oy oy oy' /* ten strings: all equal. */
Line 2,407 ⟶ 2,886:
if how=='A' then if word(x,k) <<= word(x,k-1) then return 0 /*≤ prev.?*/
end /*k*/ /* [↓] 1=true. [↑] 0=false. */
return 1 /*indicate strings have true comparison*/</langsyntaxhighlight>
{{out|output|text=&nbsp; is identical to the above REXX version.}} <br><br>
 
=={{header|RingRPL}}==
{{works with|HP|48G}}
<lang ring>
≪ '''IF''' DUP SIZE 2 < '''THEN''' 1 '''ELSE''' ≪ == ≫ DOSUBS ΠLIST '''END'''
cString1 = "hello"
≫ ‘<span style="color:blue">ALLSAME?</span>' STO
cString2 = "hello"
compare(cString1,cString2)
≪ DUP SORT ==
cString1 = "abc"
≫ ‘<span style="color:blue">ALLORDERED?</span>' STO
cString2 = "bcd"
compare(cString1,cString2)
cString1 = "bcd"
cString2 = "abc"
compare(cString1,cString2)
 
func compare aString, bString
n = strcmp(aString,bString)
if n = 0 see aString + " = " + bString + nl
but n < 0 see aString + " < " + bString + nl
but n > 0 see aString + " > " + bString + nl ok
</lang>
 
=={{header|Ruby}}==
<langsyntaxhighlight lang="ruby">strings.uniq.one? # all equal?
strings == strings.uniq.sort # ascending?</langsyntaxhighlight>
 
Short circuiting:
<langsyntaxhighlight lang="ruby">strings.all?{|str| str == strings.first} # all equal?
strings.each_cons(2).all?{|str1, str2| str1 < str2} # ascending?</langsyntaxhighlight>
 
=={{header|Rust}}==
 
<syntaxhighlight lang="rust">fn strings_are_equal(seq: &[&str]) -> bool {
<lang rust>// Note that this solution uses the feature 'slice_patterns' which is available Rust nightly!
#![feature(slice_patterns)]
 
fn strings_are_equal(seq: &[&str]) -> bool {
match seq {
&[] | &[_] => true,
&[x, y, ref tail @ ..] if x == y => strings_are_equal(&[&[y], tail].concat()),
_ => false
}
Line 2,453 ⟶ 2,918:
match seq {
&[] | &[_] => true,
&[x, y, ref tail @ ..] if x < y => asc_strings(&[&[y], tail].concat()),
_ => false
}
}</langsyntaxhighlight>
 
=={{header|S-lang}}==
"Simple Loop" and "Array Idiomatic" versions:
<langsyntaxhighlight Slang="s-lang">define equal_sl(sarr)
{
variable n = length(sarr), a0, i;
Line 2,510 ⟶ 2,975:
atest(["single_element"]);
atest(NULL);
</syntaxhighlight>
</lang>
{{out}}
<pre>"AA"
Line 2,548 ⟶ 3,013:
=={{header|Scala}}==
Functions implemented in Scala following a functional paradigm
<syntaxhighlight lang="scala">
<lang Scala>
def strings_are_equal(seq:List[String]):Boolean = seq match {
case Nil => true
Line 2,561 ⟶ 3,026:
}
 
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 2,587 ⟶ 3,052:
For known lists that are 'short-enough', the simplest solution uses 'apply', but that relies on the list being shorter than the maximum number of arguments a function can accept. Better is to write a simple loop:
 
<langsyntaxhighlight lang="scheme">
(define (compare-strings fn strs)
(or (null? strs) ; returns #t on empty list
Line 2,599 ⟶ 3,064:
(compare-strings string=? strings) ; test for all equal
(compare-strings string<? strings) ; test for in ascending order
</syntaxhighlight>
</lang>
 
=={{header|Seed7}}==
<langsyntaxhighlight lang="seed7">$ include "seed7_05.s7i";
 
const func boolean: allTheSame (in array string: strings) is func
Line 2,628 ⟶ 3,093:
end if;
end for;
end func;</langsyntaxhighlight>
 
=={{header|SenseTalk}}==
<langsyntaxhighlight lang="sensetalk">analyze ["AA","BB","CC"]
analyze ["AA","AA","AA"]
analyze ["AA","CC","BB"]
Line 2,654 ⟶ 3,119:
end repeat
return True
end isAscending</langsyntaxhighlight>
{{Out}}
<pre>
Line 2,676 ⟶ 3,141:
=={{header|Sidef}}==
Short-circuiting:
<langsyntaxhighlight lang="ruby">1..arr.end -> all{ arr[0] == arr[_] } # all equal
1..arr.end -> all{ arr[_-1] < arr[_] } # strictly ascending</langsyntaxhighlight>
 
Non short-circuiting:
<langsyntaxhighlight lang="ruby">arr.uniq.len == 1 # all equal
arr == arr.uniq.sort # strictly ascending</langsyntaxhighlight>
 
=={{header|Tailspin}}==
Note that we choose here to use 1 as true and 0 as false since Tailspin doesn't (yet?) have booleans
<langsyntaxhighlight lang="tailspin">
// matcher testing if the array contains anything not equal to the first element
templates allEqual
Line 2,709 ⟶ 3,174:
otherwise 0 !
end strictEqual
</syntaxhighlight>
</lang>
 
=={{header|Tcl}}==
The command form of the <code>eq</code> and <code>&lt;</code> operators (introduced in Tcl 8.5) handle arbitrarily many arguments and will check if they're all equal/ordered.
Making the operators work with a list of values is just a matter of using the expansion syntax with them.
<langsyntaxhighlight lang="tcl">tcl::mathop::eq {*}$strings; # All values string-equal
tcl::mathop::< {*}$strings; # All values in strict order</langsyntaxhighlight>
 
=={{header|Transd}}==
<syntaxhighlight lang="Scheme">#lang transd
 
MainModule: {
_start: (λ
(for v in [["aa","ab","ad","ae"],["ab","ab","ab","ab"]] do
(lout :boolalpha v)
(lout (not (any v (λ (ret (neq @it (get v 0)))))))
(lout (not (any Range(in: v 1 -0)
(λ (ret (leq @it (get v (- @idx 1))))))) "\n")
)
)
}</syntaxhighlight>
{{out}}
<pre>
["aa", "ab", "ad", "ae"]
false
true
 
["ab", "ab", "ab", "ab"]
true
false
</pre>
 
=={{header|VBA}}==
<syntaxhighlight lang="vb">
<lang vb>
Private Function IsEqualOrAscending(myList) As String
Dim i&, boolEqual As Boolean, boolAsc As Boolean
Line 2,737 ⟶ 3,226:
IsEqualOrAscending = "List : " & Join(myList, ",") & ", IsEqual : " & (Not boolEqual) & ", IsAscending : " & Not boolAsc
End Function
</syntaxhighlight>
</lang>
Call :
<syntaxhighlight lang="vb">
<lang vb>
Sub Main()
Dim List
Line 2,751 ⟶ 3,240:
Debug.Print IsEqualOrAscending(List)
End Sub
</syntaxhighlight>
</lang>
{{Out}}
<pre>
Line 2,764 ⟶ 3,253:
 
=={{header|VBScript}}==
<syntaxhighlight lang="vb">
<lang vb>
Function string_compare(arr)
lexical = "Pass"
Line 2,788 ⟶ 3,277:
WScript.StdOut.WriteLine string_compare(Array("AA","ACB","BB","CC"))
WScript.StdOut.WriteLine string_compare(Array("FF"))
</syntaxhighlight>
</lang>
 
{{Out}}
Line 2,812 ⟶ 3,301:
Ascending Test: Pass
</pre>
 
=={{header|V (Vlang)}}==
{{trans|go}}
<syntaxhighlight lang="v (vlang)">fn all_equal(strings []string) bool {
for s in strings {
if s != strings[0] {
return false
}
}
return true
}
fn all_less_than(strings []string) bool {
for i := 1; i < strings.len(); i++ {
if !(strings[i - 1] < s) {
return false
}
}
return true
}</syntaxhighlight>
 
=={{header|Wren}}==
{{libheader|Wren-sort}}
<langsyntaxhighlight ecmascriptlang="wren">import "./sort" for Sort
 
var areEqual = Fn.new { |strings|
Line 2,831 ⟶ 3,340:
System.print("%(b) are ascending : %(areAscending.call(b))")
System.print("%(c) are all equal : %(areEqual.call(c))")
System.print("%(d) are ascending : %(areAscending.call(d))")</langsyntaxhighlight>
 
{{out}}
Line 2,839 ⟶ 3,348:
[a, a, b] are all equal : false
[a, d, c] are ascending : false
</pre>
 
=={{header|XPL0}}==
<syntaxhighlight lang "XPL0">include xpllib; \For StrCmp
 
func AreAllEqual(Strings, Size);
int Strings, Size, I;
[for I:= 1 to Size-1 do
if StrCmp(Strings(I), Strings(0)) # 0 then return false;
return true;
];
 
func AreAscending(Strings, Size;
int Strings, Size, I;
[for I:= 1 to Size-1 do
if StrCmp(Strings(I-1), Strings(I)) >= 0 then return false;
return true;
];
 
int A, B, C, D;
[A:= ["a", "a", "a"];
B:= ["a", "b", "c"];
C:= ["a", "a", "b"];
D:= ["a", "d", "c"];
Text(0, if AreAllEqual (A, 3) then "true" else "false"); CrLf(0);
Text(0, if AreAscending(B, 3) then "true" else "false"); CrLf(0);
Text(0, if AreAllEqual (C, 3) then "true" else "false"); CrLf(0);
Text(0, if AreAscending(D, 3) then "true" else "false"); CrLf(0);
]</syntaxhighlight>
{{out}}
<pre>
true
true
false
false
</pre>
 
=={{header|XProfan}}==
<syntaxhighlight lang="xprofan">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</syntaxhighlight>
{{out}}
<pre>
list: AA,BB,CC
...is not lexically equal
...is in strict ascending order
list: AA,AA,AA
...is lexically equal
...is not in strict ascending order
list: AA,CC,BB
...is not lexically equal
...is not in strict ascending order
list: AA,ACB,BB,CC
...is not lexically equal
...is in strict ascending order
list: single_element
...is lexically equal
...is in strict ascending order
</pre>
 
=={{header|zkl}}==
These short circuit.
<langsyntaxhighlight lang="zkl">fcn allEQ(strings){ (not strings.filter1('!=(strings[0]))) }
fcn monoUp(strings){
strings.len()<2 or
strings.reduce(fcn(a,b){ if(a>=b) return(Void.Stop,False); b }).toBool()
}</langsyntaxhighlight>
<langsyntaxhighlight lang="zkl">allEQ(T("AA")).println(); //True
allEQ(T("AA","AA","AA","AA")).println(); //True
allEQ(T("A", "AA","AA","AA")).println(); //False
Line 2,855 ⟶ 3,468:
monoUp(T("a","aa","aaa","aaaa")).println(); //True
monoUp(T("a","aa","aaa","aaa")).println(); //False
monoUp(T("a","b","c","cc")).println(); //True</langsyntaxhighlight>
 
=={{header|zonnon}}==
<langsyntaxhighlight lang="zonnon">
module CompareStrings;
type
Line 2,890 ⟶ 3,503:
write("ascending?: ");writeln(ascending)
end CompareStrings.
</syntaxhighlight>
</lang>
 
=={{header|ZX Spectrum Basic}}==
{{trans|AWK}}
<langsyntaxhighlight lang="zxbasic">10 FOR j=160 TO 200 STEP 10
20 RESTORE j
30 READ n
Line 2,913 ⟶ 3,526:
180 DATA 3,"AA","CC","BB"
190 DATA 4,"AA","ACB","BB","CC"
200 DATA 1,"single_element"</langsyntaxhighlight>
55

edits