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,13 @@
OptionalSort := proc(input, {
ordering :: Or(procedures,identical("lexicographic")) := "lexicographic",
column :: posint := 1,
reverse :: truefalse := false
} )
local compare;
if ordering = "lexicographic" then
compare := (x,y)->evalb(`if`(reverse,x[column]>=y[column],x[column]<=y[column]));
else
compare := (x,y)->`if`(reverse,ordering(x[column],y),ordering(y,x));
end if;
sort( input, compare );
end proc:

View file

@ -0,0 +1,7 @@
> L := [[1, 2], [3, 4], [-5, 7]]:
> OptionalSort(L);
[[-5, 7], [1, 2], [3, 4]]
> OptionalSort(L, reverse);
[[3, 4], [1, 2], [-5, 7]]
> OptionalSort(L, reverse, column = 2);
[[-5, 7], [3, 4], [1, 2]]