Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
|
|
@ -0,0 +1,36 @@
|
|||
use strict;
|
||||
use warnings;
|
||||
use feature 'say';
|
||||
|
||||
sub merge {
|
||||
my ($x, $y) = @_;
|
||||
my @out;
|
||||
while (@$x and @$y) {
|
||||
my $t = $x->[-1] <=> $y->[-1];
|
||||
if ($t == 1) { unshift @out, pop @$x }
|
||||
elsif ($t == -1) { unshift @out, pop @$y }
|
||||
else { splice @out, 0, 0, pop(@$x), pop(@$y) }
|
||||
}
|
||||
@$x, @$y, @out
|
||||
}
|
||||
|
||||
sub strand {
|
||||
my $x = shift;
|
||||
my @out = shift @$x // return;
|
||||
for (-@$x .. -1) {
|
||||
push @out, splice @$x, $_, 1 if $x->[$_] >= $out[-1];
|
||||
}
|
||||
@out
|
||||
}
|
||||
|
||||
sub strand_sort {
|
||||
my @x = @_;
|
||||
my(@out, @strand);
|
||||
@out = merge \@out, \@strand while @strand = strand(\@x);
|
||||
@out
|
||||
}
|
||||
|
||||
my @a = map (int rand(100), 1 .. 10);
|
||||
say "Before @a";
|
||||
@a = strand_sort(@a);
|
||||
say "After @a";
|
||||
Loading…
Add table
Add a link
Reference in a new issue