multi order(@H, @T) {
my %p = @H Z[=>] @T;
my @p = %p.pairs.sort(*.key <=> *.key);
multi order(@a, $i where { @a[$i]:!exists }, 0, $h) { @a[$i] = $h }
multi order(@a, $i where { @a[$i]:!exists }, $t, $h) { order @a, $i + 1, $t - 1, $h }
multi order(@a, $i where { @a[$i]:exists }, $t, $h) { order @a, $i + 1, $t, $h }
my @a;
order @a, 0, .value, .key for @p;
say @a
}
order
(27, 21, 37, 4, 19, 52, 23, 64, 1, 7, 51, 17, 24, 50, 3, 2,
34, 40, 47, 20, 8, 56, 14, 16, 42, 38, 62, 53, 31, 41, 55, 59,
48, 12, 32, 61, 9, 60, 46, 26, 58, 25, 15, 36, 11, 44, 63, 28,
5, 54, 10, 49, 57, 30, 29, 22, 35, 39, 45, 43, 18, 6, 13, 33),
( 6, 41, 1, 49, 38, 12, 1, 0, 58, 47, 4, 17, 26, 1, 61, 12,
29, 3, 4, 11, 45, 1, 32, 5, 9, 19, 1, 4, 28, 12, 2, 2,
13, 18, 19, 3, 4, 1, 10, 16, 4, 3, 29, 5, 49, 1, 1, 24,
2, 1, 38, 7, 7, 14, 35, 25, 0, 5, 4, 19, 10, 13, 4, 12)