Data update
This commit is contained in:
parent
8e4e15fa56
commit
72eb4943cb
1853 changed files with 35514 additions and 9441 deletions
46
Task/Range-extraction/FutureBasic/range-extraction.basic
Normal file
46
Task/Range-extraction/FutureBasic/range-extraction.basic
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
void local fn DoRangeExtraction
|
||||
CFArrayRef nums = @[
|
||||
@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]
|
||||
|
||||
CFMutableArrayRef array = fn MutableArrayNew
|
||||
CFRange range
|
||||
long prevNum = NSNotFound
|
||||
|
||||
for CFNumberRef num in nums
|
||||
if ( prevNum == NSNotFound )
|
||||
range = fn CFRangeMake(intval(num),1)
|
||||
else
|
||||
if ( intval(num) == prevNum + 1 )
|
||||
range.length++
|
||||
else
|
||||
MutableArrayAddObject( array, @(range) )
|
||||
range = fn CFRangeMake(intval(num),1)
|
||||
end if
|
||||
end if
|
||||
prevNum = intval(num)
|
||||
next
|
||||
MutableArrayAddObject( array, @(range) )
|
||||
|
||||
CFMutableStringRef ranges = fn MutableStringNew
|
||||
for ValueRef value in array
|
||||
range = fn ValueRange( value )
|
||||
if ( range.length > 2 )
|
||||
if ( len(ranges) ) then MutableStringAppendString(ranges,@", ")
|
||||
MutableStringAppendFormat( ranges, @"%ld-%ld", range.location, range.location + range.length - 1 )
|
||||
else
|
||||
for long i = range.location to range.location + range.length - 1
|
||||
if ( len(ranges) ) then MutableStringAppendString(ranges,@", ")
|
||||
MutableStringAppendFormat( ranges, @"%ld", i )
|
||||
next
|
||||
end if
|
||||
next
|
||||
|
||||
print ranges
|
||||
end fn
|
||||
|
||||
fn DoRangeExtraction
|
||||
|
||||
HandleEvents
|
||||
Loading…
Add table
Add a link
Reference in a new issue