P19 - 将列表向左旋转 n 个位置。

作者:Ryan Connelly

示例

> say rotate(<a b c d e f g>.list, 3).perl;
Array.new("d", "e", "f", "g", "a", "b", "c")

源代码: P19-topo.pl

use v6;

sub rotate(@list is copy, $places is copy)
{
    $places = @list.elems + $places if $places < 0;

    for ^$places {
        @list.push: @list.shift;
    }

    @list
}

say rotate(<a b c d e f g>.list, 3).perl;
say rotate(<a b c d e f g>.list, -3).perl;