RosettaCodeData/Task/Range-expansion/Factor/range-expansion.factor
2019-09-12 10:33:56 -07:00

10 lines
295 B
Factor

USING: kernel math.parser math.ranges prettyprint regexp
sequences sequences.extras splitting ;
: expand ( str -- seq )
"," split [
R/ (?<=\d)-/ re-split [ string>number ] map
dup length 2 = [ first2 [a,b] ] when
] map-concat ;
"-6,-3--1,3-5,7-11,14,15,17-20" expand .