RosettaCodeData/Task/Range-expansion/D/range-expansion.d

9 lines
276 B
D
Raw Permalink Normal View History

2014-01-17 05:32:22 +00:00
import std.stdio, std.regex, std.conv, std.range, std.algorithm;
2013-04-10 23:57:08 -07:00
2014-01-17 05:32:22 +00:00
enum rangeEx = (string s) /*pure*/ => s.matchAll(`(-?\d+)-?(-?\d+)?,?`)
.map!q{ a[1].to!int.iota(a[1 + !a[2].empty].to!int + 1) }.join;
2013-04-10 23:57:08 -07:00
void main() {
2014-01-17 05:32:22 +00:00
"-6,-3--1,3-5,7-11,14,15,17-20".rangeEx.writeln;
2013-04-10 23:57:08 -07:00
}