Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
39
Task/Range-extraction/BASIC256/range-extraction.basic
Normal file
39
Task/Range-extraction/BASIC256/range-extraction.basic
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
arraybase 1
|
||||
dim a = {-6, -3, -2, -1, 0, 1, 3, 4, 5, 7, 8, 9, 10, 11, 14, 15, 17, 18, 19, 20}
|
||||
print formatRange(a)
|
||||
print
|
||||
|
||||
dim b = {0, 1, 2, 4, 6, 7, 8, 11, 12, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 27, 28, 29, 30, 31, 32, 33, 35, 36, 37, 38, 39}
|
||||
print formatRange(b)
|
||||
end
|
||||
|
||||
function formatRange (a)
|
||||
lb = a[?,]: ub = a[?]
|
||||
if ub = - 1 then return ""
|
||||
if lb = ub then return string(a[lb])
|
||||
rangeCount = 1
|
||||
range = string(a[lb])
|
||||
for i = lb + 1 to ub
|
||||
if a[i] = a[i - 1] + 1 then
|
||||
rangeCount += 1
|
||||
else
|
||||
if rangeCount = 1 then
|
||||
range += "," + string(a[i])
|
||||
else
|
||||
if rangeCount = 2 then
|
||||
rangeCount = 1
|
||||
range += "," + string(a[i-1]) + "," + string(a[i])
|
||||
else
|
||||
rangeCount = 1
|
||||
range += "-" + string(a[i-1]) + "," + string(a[i])
|
||||
end if
|
||||
end if
|
||||
end if
|
||||
next
|
||||
if rangeCount = 2 then
|
||||
range += "," + string(a[ub])
|
||||
else
|
||||
if rangeCount > 2 then range += "-" + string(a[ub])
|
||||
end if
|
||||
return range
|
||||
end function
|
||||
Loading…
Add table
Add a link
Reference in a new issue