diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2021-03-28 07:43:18 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-03-28 07:43:18 +0100 |
| commit | 2b7bca209817ef229d61dd89a66538d4c341d4b4 (patch) | |
| tree | 4cf6c75b1df72fb063715d6b4d52cce64694f20d /challenge-105 | |
| parent | f92ef7395704bf570cde574f3d74b63ddc77ebb9 (diff) | |
| parent | e8a582957b2da7dcbc883a475de0fbb567721b0b (diff) | |
| download | perlweeklychallenge-club-2b7bca209817ef229d61dd89a66538d4c341d4b4.tar.gz perlweeklychallenge-club-2b7bca209817ef229d61dd89a66538d4c341d4b4.tar.bz2 perlweeklychallenge-club-2b7bca209817ef229d61dd89a66538d4c341d4b4.zip | |
Merge pull request #3781 from aaronreidsmith/challenge-105
Challenge 105 - Raku
Diffstat (limited to 'challenge-105')
| -rw-r--r-- | challenge-105/aaronreidsmith/blog.txt | 1 | ||||
| -rw-r--r-- | challenge-105/aaronreidsmith/raku/ch-1.raku | 26 | ||||
| -rw-r--r-- | challenge-105/aaronreidsmith/raku/ch-2.raku | 41 |
3 files changed, 68 insertions, 0 deletions
diff --git a/challenge-105/aaronreidsmith/blog.txt b/challenge-105/aaronreidsmith/blog.txt new file mode 100644 index 0000000000..aaa883ad50 --- /dev/null +++ b/challenge-105/aaronreidsmith/blog.txt @@ -0,0 +1 @@ +https://aaronreidsmith.github.io/blog/perl-weekly-challenge-105/ diff --git a/challenge-105/aaronreidsmith/raku/ch-1.raku b/challenge-105/aaronreidsmith/raku/ch-1.raku new file mode 100644 index 0000000000..d7d7f2f12f --- /dev/null +++ b/challenge-105/aaronreidsmith/raku/ch-1.raku @@ -0,0 +1,26 @@ +#!/usr/bin/env raku + +sub challenge(Numeric $N, Numeric $k) returns Str { + my $root = $k ** (1 / $N); + $root.round(.01).Str; +} + +multi sub MAIN(Num $N, Num $k) { + say challenge($N, $k); +} + +multi sub MAIN(Bool :$test) { + use Test; + + my @tests = ( + (5, 248832, '12'), + (5, 34, '2.02'), + (5.5, 34.6, '1.9') # Should accept any Numeric + ); + + for @tests -> ($N, $k, $expected) { + is(challenge($N, $k), $expected); + } + + done-testing; +} diff --git a/challenge-105/aaronreidsmith/raku/ch-2.raku b/challenge-105/aaronreidsmith/raku/ch-2.raku new file mode 100644 index 0000000000..660e2952af --- /dev/null +++ b/challenge-105/aaronreidsmith/raku/ch-2.raku @@ -0,0 +1,41 @@ +#!/usr/bin/env raku + +sub challenge(Str $name) returns Str { + my $X = $name.wordcase; + my $Y = $X ~~ /^[A|E|I|O|U|Y]<-[aeiouy]>/ ?? $X.lc !! $X.substr(1); + + qq:to/END/; + $X, $X, bo-{$X.starts-with('B') ?? '' !! 'b'}$Y + Bonana-fanna fo-{$X.starts-with('F') ?? '' !! 'f'}$Y + Fee fi mo-{$X.starts-with('M') ?? '' !! 'm'}$Y + $X! + END +} + +multi sub MAIN(Str $name) { + say challenge($name); +} + +multi sub MAIN(Bool :$test) { + use Test; + + my @tests = ( + ('Katie', "Katie, Katie, bo-batie\nBonana-fanna fo-fatie\nFee fi mo-matie\nKatie!\n"), + ('Aaron', "Aaron, Aaron, bo-baron\nBonana-fanna fo-faron\nFee fi mo-maron\nAaron!\n"), + # Should work with lowercase or uppercase input + ('valerie', "Valerie, Valerie, bo-balerie\nBonana-fanna fo-falerie\nFee fi mo-malerie\nValerie!\n"), + # Should work with names that start with vowels followed by consonants + ('AMY', "Amy, Amy, bo-bamy\nBonana-fanna fo-famy\nFee fi mo-mamy\nAmy!\n"), + ('Everett', "Everett, Everett, bo-beverett\nBonana-fanna fo-feverett\nFee fi mo-meverett\nEverett!\n"), + # Wikipedia special cases + ('Billy', "Billy, Billy, bo-illy\nBonana-fanna fo-filly\nFee fi mo-milly\nBilly!\n"), + ('Fred', "Fred, Fred, bo-bred\nBonana-fanna fo-red\nFee fi mo-mred\nFred!\n"), + ('Marsha', "Marsha, Marsha, bo-barsha\nBonana-fanna fo-farsha\nFee fi mo-arsha\nMarsha!\n") + ); + + for @tests -> ($name, $expected) { + is(challenge($name), $expected); + } + + done-testing; +} |
