Skip to content

Instantly share code, notes, and snippets.

@japhb
japhb / median-of-three-conjecture.p6
Created October 29, 2009 20:32 — forked from jnthn/gist:221659
Working out a conjectured syntax for slicing long lists in a Perl 6 signature
multi quicksort([$head, *@front, $mid, *@back, $tail]) {
my ($pivot, @others) := median-of-three($head, $mid, $tail);
my @rest := |@others, |@front, |@back;
quicksort(@rest.grep(* < $pivot)),
$pivot,
quicksort(@rest.grep(* >= $pivot))
}
multi quicksort([$a, $b]) { $a < $b ?? $a, $b !! $b, $a }
multi quicksort(@a [$a?]) { @a }