P10 - 列表的游程编码。
作者:Ryan Connelly
示例
> say encode(<a a a a a b b c b d e e>.list).perl; ([5, "a"], [2, "b"], [1, "c"], [1, "b"], [1, "d"], [2, "e"]).list
源代码: P10-topo.pl
use v6; sub encode(@ls) { my @list = @ls[*]; gather while @list.elems { my $value = @list[0]; my $count = 0; while @list.elems and @list[0] ~~ $value { $count++; shift @list } take [$count, $value]; } } say encode(<a a a a a b b c b d e e>).list.perl;