How to resolve the algorithm Range expansion step by step in the Ring programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Range expansion step by step in the Ring 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 Ring programming language
Source code in the ring programming language
# Project : Range expansion
int = "-6,-3--1,3-5,7-11,14,15,17-20"
int = str2list(substr(int, ",", nl))
newint = []
for n=1 to len(int)
nrint = substr(int[n], "-")
nrint2 = substr(int[n], "--")
if nrint2 > 0
temp1 = left(int[n], nrint2 -1)
temp2 = right(int[n], len(int[n]) - nrint2)
add(newint, [temp1,temp2])
else
if len(int[n]) <= 2
add(newint, [int[n], ""])
else
if nrint > 0 and nrint2 = 0
temp1 = left(int[n], nrint - 1)
temp2 = right(int[n], len(int[n]) - nrint)
add(newint, [temp1,temp2])
ok
ok
ok
next
showarray(newint)
func showarray(vect)
see "["
svect = ""
for n = 1 to len(vect)
if newint[n][2] != ""
for nr = newint[n][1] to newint[n][2]
svect = svect +"" + nr + ", "
next
else
svect = svect +"" + newint[n][1] + ", "
ok
next
svect = left(svect, len(svect) - 2)
see svect
see "]" + nl
You may also check:How to resolve the algorithm Percolation/Mean run density step by step in the Perl programming language
You may also check:How to resolve the algorithm Non-decimal radices/Output step by step in the Haskell programming language
You may also check:How to resolve the algorithm Define a primitive data type step by step in the Retro programming language
You may also check:How to resolve the algorithm Bulls and cows/Player step by step in the Ada programming language
You may also check:How to resolve the algorithm Convert seconds to compound duration step by step in the Delphi programming language