Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
22
Task/Range-extraction/MiniScript/range-extraction.mini
Normal file
22
Task/Range-extraction/MiniScript/range-extraction.mini
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
extractRange = function(ints)
|
||||
result = []
|
||||
idx = 0
|
||||
while idx < ints.len
|
||||
runLen = 1
|
||||
while idx+runLen < ints.len and ints[idx+runLen] == ints[idx] + runLen
|
||||
runLen = runLen + 1
|
||||
end while
|
||||
if runLen > 2 then
|
||||
result.push ints[idx] + "-" + ints[idx+runLen-1]
|
||||
idx = idx + runLen
|
||||
else
|
||||
result.push ints[idx]
|
||||
idx = idx + 1
|
||||
end if
|
||||
end while
|
||||
return join(result, ",")
|
||||
end function
|
||||
|
||||
test = [ 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 extractRange(test)
|
||||
Loading…
Add table
Add a link
Reference in a new issue