diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2021-01-25 18:44:30 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-01-25 18:44:30 +0000 |
| commit | aada61e5eb256d12fcae121374efd10a5b59391a (patch) | |
| tree | 38f470547a8f79a04257dcb00655d7f731ea16cc | |
| parent | c2e3d94308259dfeed2f131426c365adb88a9663 (diff) | |
| parent | aaee0c476eb181bb94ef0080db1258b67c1cba7b (diff) | |
| download | perlweeklychallenge-club-aada61e5eb256d12fcae121374efd10a5b59391a.tar.gz perlweeklychallenge-club-aada61e5eb256d12fcae121374efd10a5b59391a.tar.bz2 perlweeklychallenge-club-aada61e5eb256d12fcae121374efd10a5b59391a.zip | |
Merge pull request #3370 from andemark/branch-for-challenge-097
Challenge 97 Solutions (Raku)
| -rw-r--r-- | challenge-097/mark-anderson/raku/ch-1.raku | 19 | ||||
| -rw-r--r-- | challenge-097/mark-anderson/raku/ch-2.raku | 16 |
2 files changed, 35 insertions, 0 deletions
diff --git a/challenge-097/mark-anderson/raku/ch-1.raku b/challenge-097/mark-anderson/raku/ch-1.raku new file mode 100644 index 0000000000..4db6d53f86 --- /dev/null +++ b/challenge-097/mark-anderson/raku/ch-1.raku @@ -0,0 +1,19 @@ +#!/usr/bin/env raku + +use Test; +plan 4; + +my $S = "THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG"; +my $R = "QEB NRFZH YOLTK CLU GRJMP LSBO QEB IXWV ALD"; + +is caesar($S, 3), $R; +is caesar($S, 29), $R; +is caesar($S, -23), $R; +is caesar($S, -49), $R; + +sub caesar($S, $N) +{ + my @A = "A".."Z"; + + $S.trans: @A => @A.rotate: -$N; +} diff --git a/challenge-097/mark-anderson/raku/ch-2.raku b/challenge-097/mark-anderson/raku/ch-2.raku new file mode 100644 index 0000000000..377566e6d4 --- /dev/null +++ b/challenge-097/mark-anderson/raku/ch-2.raku @@ -0,0 +1,16 @@ +#!/usr/bin/env raku + +use Test; +plan 4; + +is flips("101100101", 3), 1; +is flips("10110111", 4), 2; +is flips("1111000010101100", 2), 8; +is flips("1111000010101100", 4), 8; + +sub flips($B, $S) +{ + my ($head, @tail) = $B.comb: $S; + + .elems given flat @tail.map({ ("0b$head" +^ "0b$_").base(2).comb("1") }); +} |
