diff options
| author | Mark Anderson <mark@frontrangerunner.com> | 2020-10-26 15:13:40 -0600 |
|---|---|---|
| committer | Mark Anderson <mark@frontrangerunner.com> | 2020-10-26 15:13:40 -0600 |
| commit | d51f228ce169ba54dd98cefac7b00f183ded7710 (patch) | |
| tree | 40a182c2544abc3abc1ac1812a66d6cb93c13dc2 /challenge-084/mark-anderson | |
| parent | b1f35767c59d05db71b40e53410d96173d838803 (diff) | |
| download | perlweeklychallenge-club-d51f228ce169ba54dd98cefac7b00f183ded7710.tar.gz perlweeklychallenge-club-d51f228ce169ba54dd98cefac7b00f183ded7710.tar.bz2 perlweeklychallenge-club-d51f228ce169ba54dd98cefac7b00f183ded7710.zip | |
Challenge 84 Solutions (Raku)
Diffstat (limited to 'challenge-084/mark-anderson')
| -rw-r--r-- | challenge-084/mark-anderson/raku/ch-2.p6 | 27 |
1 files changed, 19 insertions, 8 deletions
diff --git a/challenge-084/mark-anderson/raku/ch-2.p6 b/challenge-084/mark-anderson/raku/ch-2.p6 index afa0a45ff8..4eecb2506a 100644 --- a/challenge-084/mark-anderson/raku/ch-2.p6 +++ b/challenge-084/mark-anderson/raku/ch-2.p6 @@ -1,5 +1,5 @@ use Test; -plan 5; +plan 7; my @matrix; @@ -40,6 +40,21 @@ ok square-count(@matrix) == 2, "Example 4"; ok square-count(@matrix) == 2, "Example 5"; +@matrix = < 1 1 1 1 >, + < 1 1 1 1 >, + < 1 1 1 1 >, + < 1 1 1 1 >, + < 1 1 1 1 >; + +ok square-count(@matrix) == 20, "Example 6"; + +@matrix = < 1 1 1 1 1 >, + < 1 1 1 1 1 >, + < 1 1 1 1 1 >, + < 1 1 1 1 1 >; + +ok square-count(@matrix) == 20, "Example 7"; + sub square-count(@matrix) { my $count = 0; @@ -48,13 +63,9 @@ sub square-count(@matrix) { next unless @indices.elems >= 2; - for @indices.combinations(2) -> @c { - my $skip = @c.tail - @c.head; - - if @matrix[$i+$skip][@c.head] and - @matrix[$i+$skip][@c.tail] { - $count++; - } + for @indices.combinations(2) -> [$h, $t] { + my $skip = $i + $t - $h; + $count++ if @matrix[$skip][$h] and @matrix[$skip][$t]; } } |
