Add tasks for all the new languages
This commit is contained in:
parent
9dc3c2bb62
commit
bba7bfd280
13208 changed files with 134745 additions and 0 deletions
|
|
@ -0,0 +1,36 @@
|
|||
func merge(x, y) {
|
||||
var out = [];
|
||||
while (x && y) {
|
||||
given (x[-1] <=> y[-1]) {
|
||||
when ( 1) { out.prepend(x.pop) }
|
||||
when (-1) { out.prepend(y.pop) }
|
||||
default { out.prepend(x.pop, y.pop) }
|
||||
}
|
||||
}
|
||||
x + y + out;
|
||||
}
|
||||
|
||||
func strand(x) {
|
||||
x || return [];
|
||||
var out = [x.shift];
|
||||
if (x.len) {
|
||||
for i in (-x.len .. -1) {
|
||||
if (x[i] >= out[-1]) {
|
||||
out.append(x.pop_at(i));
|
||||
}
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
func strand_sort(x) {
|
||||
var out = [];
|
||||
while (var strd = strand(x)) {
|
||||
out = merge(out, strd);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
var a = 10.of { 100.irand };
|
||||
say "Before: #{a}";
|
||||
say "After: #{strand_sort(a)}";
|
||||
Loading…
Add table
Add a link
Reference in a new issue