Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
|
|
@ -0,0 +1,20 @@
|
|||
sub pancake_sort ( @a is copy ) {
|
||||
my $endpoint = @a.end;
|
||||
while $endpoint > 0 and not [<] @a {
|
||||
my $max_i = [0..$endpoint].max: { @a[$_] };
|
||||
my $max = @a[$max_i];
|
||||
if @a[$endpoint] == $max {
|
||||
$endpoint-- while @a[$endpoint] == $max;
|
||||
next;
|
||||
}
|
||||
# @a[$endpoint] is not $max, so it needs flipping;
|
||||
# Flip twice if max is not already at the top.
|
||||
@a[0..$max_i] .= reverse if $max_i != 0;
|
||||
@a[0..$endpoint] .= reverse;
|
||||
$endpoint--;
|
||||
}
|
||||
return @a;
|
||||
}
|
||||
my @data = 6, 7, 2, 1, 8, 9, 5, 3, 4;
|
||||
say 'input = ' ~ @data;
|
||||
say 'output = ' ~ @data.&pancake_sort;
|
||||
Loading…
Add table
Add a link
Reference in a new issue