P17 - 将一个列表分成两部分;第一部分的长度是给定的。
作者:David Romano
规范
P17 (*) Split a list into two parts; the length of the first part is given. Do not use any predefined predicates.
示例
> say bisect(<a b c d e f g h i k>, 3).perl (["a", "b", "c"], ["d", "e", "f", "g", "h", "i", "k"])
源代码:P17-unobe.pl
use v6; my @l = <a b c d e f g h i k>; sub prob17(@in, $n) { if @in.end < $n { return @in } else { my $beg = [gather { for 0...$n-1 { take @in[$_] } }]; my $end = [gather { for [email protected] { take @in[$_] } }]; return ($beg, $end); } } say @l.perl; say prob17(@l, 3).perl;