diff options
| author | Mark A <andemark@a-iot1t.uch.ad.pvt> | 2021-03-22 06:45:04 -0600 |
|---|---|---|
| committer | Mark A <andemark@a-iot1t.uch.ad.pvt> | 2021-03-22 06:45:04 -0600 |
| commit | 478817b986b42b9dab5c7e9c9098b2732759c7fa (patch) | |
| tree | c19d826a7bba64fd1138902ab69adbe09024c49f /challenge-105 | |
| parent | 7c2d89ebc351875ef67e4e351cbb8d813852d8fe (diff) | |
| download | perlweeklychallenge-club-478817b986b42b9dab5c7e9c9098b2732759c7fa.tar.gz perlweeklychallenge-club-478817b986b42b9dab5c7e9c9098b2732759c7fa.tar.bz2 perlweeklychallenge-club-478817b986b42b9dab5c7e9c9098b2732759c7fa.zip | |
initial
Diffstat (limited to 'challenge-105')
| -rw-r--r-- | challenge-105/mark-anderson/raku/ch-1.raku | 19 | ||||
| -rw-r--r-- | challenge-105/mark-anderson/raku/ch-2.raku | 51 |
2 files changed, 70 insertions, 0 deletions
diff --git a/challenge-105/mark-anderson/raku/ch-1.raku b/challenge-105/mark-anderson/raku/ch-1.raku new file mode 100644 index 0000000000..9e999f44b4 --- /dev/null +++ b/challenge-105/mark-anderson/raku/ch-1.raku @@ -0,0 +1,19 @@ +#!/usr/bin/env raku + +use Test; +plan 2; + +is nth-root(5, 248832), 12; +is nth-root(5, 34), 2.02; + +sub nth-root($n, $k) +{ + my $x = .narrow given $k ** (1/$n); + + unless $x ~~ UInt + { + $x .= fmt("%.2f"); + } + + $x; +} diff --git a/challenge-105/mark-anderson/raku/ch-2.raku b/challenge-105/mark-anderson/raku/ch-2.raku new file mode 100644 index 0000000000..0364d8dc63 --- /dev/null +++ b/challenge-105/mark-anderson/raku/ch-2.raku @@ -0,0 +1,51 @@ +#!/usr/bin/env raku + +# I have no idea how to test whether the emphasis is on the first +# or second syllable so I'm just testing for consonants and vowels. + +use Test; +plan 4; + +is name-game("Katie"), chomp q:to/END/; + Katie, Katie, bo-batie, + Bonana-fanna fo-fatie + Fee fi mo-matie + Katie! + END + +is name-game("Aaron"), chomp q:to/END/; + Aaron, Aaron, bo-baaron, + Bonana-fanna fo-faaron + Fee fi mo-maaron + Aaron! + END + +is name-game("Charles"), chomp q:to/END/; + Charles, Charles, bo-barles, + Bonana-fanna fo-farles + Fee fi mo-marles + Charles! + END + +is name-game("Shirley"), chomp q:to/END/; + Shirley, Shirley, bo-birley, + Bonana-fanna fo-firley + Fee fi mo-mirley + Shirley! + END + +sub name-game($X) +{ + my $vowels = rx/ <[AEIOUaeiou]>+ /; + + my $consonants = rx/ <[A..Za..z]-[AEIOUaeiou]>+ /; + + my $start = $X ~~ / ^ [$vowels|$consonants] /; + + my $Y = $start ~~ $consonants ?? $X.subst($start, "") !! lc $X; + + .join("\n") given "$X, $X, bo-b" ~ $Y ~ ",", + "Bonana-fanna fo-f" ~ $Y, + "Fee fi mo-m" ~ $Y, + $X ~ "!"; +} |
