Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View file

@ -0,0 +1,37 @@
ExpandRanges := proc( s :: string )
uses StringTools;
local DoOne := proc( input )
uses StringTools;
local lo, hi, pos;
if IsDigit( input ) or input[ 1 ] = "-"
and IsDigit( input[ 2 .. -1 ] ) then
parse( input )
else
pos := Search( "--", input );
if pos > 0 then
lo := input[ 1 .. pos - 1 ];
hi := input[ 1 + pos .. -1 ];
elif input[ 1 ] = "-" then
pos := FirstFromLeft( "-", input[ 2 .. -1 ] );
if pos = 0 then
lo := input;
hi := lo
else
lo := input[ 1 .. pos ];
hi := input[ 2 + pos .. -1 ];
end if;
else
pos := FirstFromLeft( "-", input );
if pos = 0 then
error "incorrect syntax"
end if;
lo := input[ 1 .. pos - 1 ];
hi := input[ 1 + pos .. -1 ];
end if;
lo := parse( lo );
hi := parse( hi );
seq( lo .. hi )
end if
end proc:
map( DoOne, map( Trim, Split( s, "," ) ) )
end proc:

View file

@ -0,0 +1,3 @@
> rng := "-6,-3--1,3-5,7-11,14,15,17-20":
> ExpandRanges( rng );
[-6, -3, -2, -1, 3, 4, 5, 7, 8, 9, 10, 11, 14, 15, 17, 18, 19, 20]

View file

@ -0,0 +1,3 @@
> rng := "-6,-3-1,3-5,7-11,14,15,17-20":
> ExpandRanges( rng );
[-6, -3, -2, -1, 0, 1, 3, 4, 5, 7, 8, 9, 10, 11, 14, 15, 17, 18, 19, 20]