diff options
| author | Mark <53903062+andemark@users.noreply.github.com> | 2023-05-08 08:10:27 +0000 |
|---|---|---|
| committer | Mark <53903062+andemark@users.noreply.github.com> | 2023-05-08 08:10:27 +0000 |
| commit | 6c57247b72e69defedabf3d79baf38dec58416ec (patch) | |
| tree | 65faea2a2c23de5cd765371cd438ba9a24cbac08 | |
| parent | 488c528fc8725f3e183eae4073709f95edca33fb (diff) | |
| download | perlweeklychallenge-club-6c57247b72e69defedabf3d79baf38dec58416ec.tar.gz perlweeklychallenge-club-6c57247b72e69defedabf3d79baf38dec58416ec.tar.bz2 perlweeklychallenge-club-6c57247b72e69defedabf3d79baf38dec58416ec.zip | |
Challenge 216 Solutions (Raku)
| -rw-r--r-- | challenge-216/mark-anderson/raku/ch-1.raku | 12 | ||||
| -rw-r--r-- | challenge-216/mark-anderson/raku/ch-2.raku | 26 |
2 files changed, 38 insertions, 0 deletions
diff --git a/challenge-216/mark-anderson/raku/ch-1.raku b/challenge-216/mark-anderson/raku/ch-1.raku new file mode 100644 index 0000000000..135b6a47c2 --- /dev/null +++ b/challenge-216/mark-anderson/raku/ch-1.raku @@ -0,0 +1,12 @@ +#!/usr/bin/env raku +use Test; + +is-deeply reg-num(<abc abcd bcd>, "AB1 2CD"), ("abcd",); +is-deeply reg-num(<job james bjorg>, "007 JB"), <job bjorg>; +is-deeply reg-num(<crack road rac>, "C7 RA2"), <crack rac>; + +sub reg-num($words, $reg) +{ + my $r = $reg.comb(/<upper>/)>>.lc; + $words.Slip.grep({ .comb (>=) $r }) +} diff --git a/challenge-216/mark-anderson/raku/ch-2.raku b/challenge-216/mark-anderson/raku/ch-2.raku new file mode 100644 index 0000000000..ca3cbd6f42 --- /dev/null +++ b/challenge-216/mark-anderson/raku/ch-2.raku @@ -0,0 +1,26 @@ +#!/usr/bin/env raku +use Test; + +is word-stickers(<perl raku python>, <peon>), 2; +is word-stickers(<love hate angry>, <goat>), 3; +is word-stickers(<come nation delta>, <accommodation>), 4; +is word-stickers(<come country delta>, <accommodation>), 0; +is word-stickers(<come accommodations country delta>, <accommodation>), 1; +is word-stickers(<the quick brown fox jumps over the lazy dog>, <supercalifragilisticexpialidocious>), 18; +is word-stickers(<the five boxing wizards jump quickly>, <supercalifragilisticexpialidocious>), 12; +is word-stickers(<pack my box with five dozen liquor jugs>, <supercalifragilisticexpialidocious>), 15; + +sub word-stickers($s, $w) +{ + return 0 if $w.comb (-) $s.comb(/<lower>/); + + my @stickers = $s>>.comb>>.Bag; + my $word = $w.comb.BagHash; + + .elems given gather while $word + { + my $i = @stickers.map({ ($_ (&) $word).total }).maxpairs.head.key + andthen .take; + $word.remove(@stickers[$i].kxxv) + } +} |
