June 2018 Update
This commit is contained in:
parent
ba8067c3b7
commit
22f33d4004
5278 changed files with 84726 additions and 14379 deletions
18
Task/Range-extraction/Factor/range-extraction.factor
Normal file
18
Task/Range-extraction/Factor/range-extraction.factor
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
USING: formatting io kernel math math.parser sequences
|
||||
splitting.monotonic ;
|
||||
IN: rosetta-code.range-extraction
|
||||
|
||||
: make-range ( seq -- str )
|
||||
[ first ] [ last ] bi "%d-%d" sprintf ;
|
||||
|
||||
: make-atomic ( seq -- str ) [ number>string ] map "," join ;
|
||||
|
||||
: extract-range ( seq -- str )
|
||||
[ - -1 = ] monotonic-split
|
||||
[ dup length 2 > [ make-range ] [ make-atomic ] if ] map
|
||||
"," join ;
|
||||
|
||||
{
|
||||
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
|
||||
} extract-range print
|
||||
Loading…
Add table
Add a link
Reference in a new issue