How to resolve the algorithm Range expansion step by step in the S-lang programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Range expansion step by step in the S-lang programming language
Table of Contents
Problem Statement
A format for expressing an ordered list of integers is to use a comma separated list of either Example The list of integers: Is accurately expressed by the range expression: (And vice-versa).
Expand the range description: Note that the second element above, is the range from minus 3 to minus 1.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Range expansion step by step in the S-lang programming language
Source code in the s-lang programming language
variable r_expres = "-6,-3--1,3-5,7-11,14,15,17-20", s, r_expan = {}, dpos, i;
foreach s (strchop(r_expres, ',', 0))
{
% S-Lang built-in RE's are fairly limited, and have a quirk:
% grouping is done with \\( and \\), not ( and )
% [PCRE and Oniguruma RE's are available via standard libraries]
if (string_match(s, "-?[0-9]+\\(-\\)-?[0-9]+", 1)) {
(dpos, ) = string_match_nth(1);
% Create/loop-over a "range array": from num before - to num after it:
foreach i ( [integer(substr(s, 1, dpos)) : integer(substr(s, dpos+2, -1))] )
list_append(r_expan, string(i));
}
else
list_append(r_expan, s);
}
print(strjoin(list_to_array(r_expan), ", "));
You may also check:How to resolve the algorithm Secure temporary file step by step in the Delphi programming language
You may also check:How to resolve the algorithm User input/Graphical step by step in the LabVIEW programming language
You may also check:How to resolve the algorithm Word wrap step by step in the EasyLang programming language
You may also check:How to resolve the algorithm SHA-1 step by step in the PowerShell programming language
You may also check:How to resolve the algorithm Sorting algorithms/Insertion sort step by step in the Yorick programming language