P09 - 将列表中连续重复的元素打包成子列表。
作者:David Romano
规范
P09 (**) Pack consecutive duplicates of list elements into sublists. If a list contains repeated elements they should be placed in separate sublists.
示例
> pack_dup(<a a a a b c c a a d e e e e>).perl.say [["a","a","a","a"],["b"],["c","c"],["a","a"],["d"],["e","e","e","e"]]
源代码:P09-unobe.pl
use v6; my @l = <a a a a b c c a a d e e e e>; sub prob09 (@in) { return gather while @in.elems { my $val = @in[0]; take [gather while @in.elems and @in[0] ~~ $val { take shift @in }]; } } say ~@l; say prob09(@l).list.perl;