How to resolve the algorithm Range expansion step by step in the Yabasic programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Range expansion step by step in the Yabasic 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 Yabasic programming language
Source code in the yabasic programming language
print RangeExpand$("-6,-3--1,3-5,7-11,14,15,17-20")
sub RangeExpand$(s$)
local w$(1), n, i, r$, p, a, b
n = token(s$, w$(), ",")
for i = 1 to n
p = instr(w$(i), "-", 2)
if p then
a = val(left$(w$(i), p-1))
b = val(right$(w$(i), len(w$(i)) - p))
repeat
r$ = r$ + str$(a) + ","
a = a + 1
until(a > b)
else
r$ = r$ + w$(i) + ","
end if
next
return left$(r$, len(r$) - 1)
end sub
You may also check:How to resolve the algorithm Levenshtein distance step by step in the PL/I programming language
You may also check:How to resolve the algorithm Averages/Root mean square step by step in the Julia programming language
You may also check:How to resolve the algorithm Walk a directory/Recursively step by step in the Factor programming language
You may also check:How to resolve the algorithm Sorting algorithms/Patience sort step by step in the D programming language
You may also check:How to resolve the algorithm Deconvolution/1D step by step in the zkl programming language