diff options
| -rw-r--r-- | challenge-211/wambash/raku/ch-1.raku | 19 | ||||
| -rw-r--r-- | challenge-211/wambash/raku/ch-2.raku | 37 |
2 files changed, 56 insertions, 0 deletions
diff --git a/challenge-211/wambash/raku/ch-1.raku b/challenge-211/wambash/raku/ch-1.raku new file mode 100644 index 0000000000..91aef076c5 --- /dev/null +++ b/challenge-211/wambash/raku/ch-1.raku @@ -0,0 +1,19 @@ +#!/usr/bin/env raku + +sub toeplitz-matrix (+@matrix) { + @matrix + andthen .rotor: 2 => -1 + andthen .map: -> (@x,@y) { @x.head(*-1) eqv @y.tail(*-1) }\ + andthen .all +} + +multi MAIN (Bool :test($)!) { + use Test; + is-deeply toeplitz-matrix([4, 3, 2, 1], [5, 4, 3, 2],[6, 5, 4, 3],),True; + is-deeply toeplitz-matrix([1,2,3],[3, 2, 1],),False; + done-testing; +} + +multi MAIN (*@matrix) { + say ?toeplitz-matrix @matrix.map: *.comb: /\d+/ +} diff --git a/challenge-211/wambash/raku/ch-2.raku b/challenge-211/wambash/raku/ch-2.raku new file mode 100644 index 0000000000..ab6f2a060c --- /dev/null +++ b/challenge-211/wambash/raku/ch-2.raku @@ -0,0 +1,37 @@ +#!/usr/bin/env raku + +sub average { @^a.sum / @^a.elems } + +sub split-same-average (+@nums) { + my $average = average @nums; + my $elems-limit = @nums.elems div 2; + + @nums + andthen .combinations( 1..$elems-limit ) + andthen .first: { .&average == $average }, +} + +multi MAIN (Bool :test($)!) { + use Test; + is split-same-average(1, 2, 3, 4, 5, 6, 7, 8), (1,8); + is split-same-average(1,3), Nil; + subtest { + plan 2; + my @twenty = < + 44531 73257 49118 89580 + 25846 88015 19523 99285 + 75574 80036 10796 89896 + 77776 69138 75824 80610 + 47566 1623 20068 5294 + >; + with split-same-average(@twenty) { + is .&average, average(@twenty); + is .elems, @twenty.elems div 2; + } + } + done-testing; +} + +multi MAIN (*@nums) { + say split-same-average @nums +} |
