How to resolve the algorithm Order two numerical lists step by step in the Picat programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Order two numerical lists step by step in the Picat programming language
Table of Contents
Problem Statement
Write a function that orders two lists or arrays filled with numbers. The function should accept two lists as arguments and return true if the first list should be ordered before the second, and false otherwise. The order is determined by lexicographic order: Comparing the first element of each list. If the first elements are equal, then the second elements should be compared, and so on, until one of the list has no more elements. If the first list runs out of elements the result is true. If the second list or both run out of elements the result is false. Note: further clarification of lexicographical ordering is expounded on the talk page here and here.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Order two numerical lists step by step in the Picat programming language
Source code in the picat programming language
go =>
Tests = [
[[1,2,3], [1,2,3]],
[[1,2,3], [1,2,3,4]],
[[1,2,2], [1,2,3]],
[[1,2,4], [1,2,3]],
[1..10 , 1..8],
[[] , []],
[[] , [1]],
[[1] , [] ],
[[-1,2,3,6,5],[-1,2,3,5,6]],
[[-1,2,3,-5,6],[-1,2,3,-6,5]]
],
foreach([L1,L2] in Tests)
printf("%w @< %w: %w\n",L1,L2,cond(L1 @< L2,true,false))
end,
nl.
You may also check:How to resolve the algorithm Sequence of primes by trial division step by step in the Scala programming language
You may also check:How to resolve the algorithm Balanced brackets step by step in the GDScript programming language
You may also check:How to resolve the algorithm Convert decimal number to rational step by step in the PL/I programming language
You may also check:How to resolve the algorithm Honaker primes step by step in the C++ programming language
You may also check:How to resolve the algorithm Main step of GOST 28147-89 step by step in the Nim programming language