diff options
| author | Util <bruce.gray@acm.org> | 2024-06-02 11:39:05 -0500 |
|---|---|---|
| committer | Util <bruce.gray@acm.org> | 2024-06-02 11:39:05 -0500 |
| commit | 1b336e63dabeb77abdacf337d4a7b18f3ccc8592 (patch) | |
| tree | a4301cf97d27f0261d8a6e844be7e57554c1e9da | |
| parent | 1166e1c75017c2a5a339ae80aff9361d7347df38 (diff) | |
| download | perlweeklychallenge-club-1b336e63dabeb77abdacf337d4a7b18f3ccc8592.tar.gz perlweeklychallenge-club-1b336e63dabeb77abdacf337d4a7b18f3ccc8592.tar.bz2 perlweeklychallenge-club-1b336e63dabeb77abdacf337d4a7b18f3ccc8592.zip | |
Add TWC 271 solutions by Bruce Gray, in Raku only.
| -rw-r--r-- | challenge-271/bruce-gray/raku/ch-1.raku | 13 | ||||
| -rw-r--r-- | challenge-271/bruce-gray/raku/ch-2.raku | 17 |
2 files changed, 30 insertions, 0 deletions
diff --git a/challenge-271/bruce-gray/raku/ch-1.raku b/challenge-271/bruce-gray/raku/ch-1.raku new file mode 100644 index 0000000000..641c6f8d91 --- /dev/null +++ b/challenge-271/bruce-gray/raku/ch-1.raku @@ -0,0 +1,13 @@ +sub task1 ( @matrix --> UInt ) { + return 1 + @matrix».sum.maxpairs.head.key; +} + + +use Test; plan +constant @tests1 = + ( 1, ( (0, 1), (1, 0) ) ), + ( 2, ( (0, 0, 0), (1, 0, 1) ) ), + ( 2, ( (0, 0), (1, 1), (0, 0) ) ), +; +for @tests1 -> ($expected, @matrix) { + is task1(@matrix), $expected, "@matrix[]"; +} diff --git a/challenge-271/bruce-gray/raku/ch-2.raku b/challenge-271/bruce-gray/raku/ch-2.raku new file mode 100644 index 0000000000..94a0abb763 --- /dev/null +++ b/challenge-271/bruce-gray/raku/ch-2.raku @@ -0,0 +1,17 @@ +sub pop-count { $^number.base(2).comb('1').elems } # From challenge-258; could also have done any of: + # .comb(/1+/)».chars.sum + # .comb(/1+/).join.chars + # .subst(:g, '0').chars + +sub task2 ( @ns --> Seq ) { + return @ns.sort: { +.&pop-count, +$_ }; +} + + +use Test; plan +constant @tests = + ( (0, 1, 2, 3, 4, 5, 6, 7, 8) , (0, 1, 2, 4, 8, 3, 5, 6, 7) ), + ( (1024, 512, 256, 128, 64) , (64, 128, 256, 512, 1024) ), +; +for @tests -> (@in, @expected) { + is-deeply task2(@in), @expected, "@in[]"; +} |
