Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 7d9c16311e
Fetching contributors…

Cannot retrieve contributors at this time

file 21 lines (18 sloc) 0.563 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
use v6;

# Specification:
# P17 (*) Split a list into two parts; the length of the first part is given.
# Do not use any predefined predicates.
# Example:
# > say bisect(<a b c d e f g h i k>,3).perl
# (["a", "b", "c"], ["d", "e", "f", "g", "h", "i", "k"])


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 $n...@in.end { take @in[$_] } }];
        return ($beg, $end);
    }
}
say @l.perl;
say prob17(@l, 3).perl;
Something went wrong with that request. Please try again.