aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2021-04-05 00:07:25 +0100
committerGitHub <noreply@github.com>2021-04-05 00:07:25 +0100
commitf386ca51e09788c1c5585b8e748c6712dadba5f8 (patch)
treed663c83c7e5d9902dae80c7046385ee7e08f653f
parente4209b3ea3cb87c37f369e85fdd343846a811da1 (diff)
parent3865c78aefff6f4ce248029aa0a4f69fe52ddbdf (diff)
downloadperlweeklychallenge-club-f386ca51e09788c1c5585b8e748c6712dadba5f8.tar.gz
perlweeklychallenge-club-f386ca51e09788c1c5585b8e748c6712dadba5f8.tar.bz2
perlweeklychallenge-club-f386ca51e09788c1c5585b8e748c6712dadba5f8.zip
Merge pull request #3823 from mimosinnet/branch-for-challenge-106
Solutions to challenge 106
-rw-r--r--challenge-106/mimosinnet/raku/ch-1.raku38
-rw-r--r--challenge-106/mimosinnet/raku/ch-2.raku40
2 files changed, 78 insertions, 0 deletions
diff --git a/challenge-106/mimosinnet/raku/ch-1.raku b/challenge-106/mimosinnet/raku/ch-1.raku
new file mode 100644
index 0000000000..c1b205eb0f
--- /dev/null
+++ b/challenge-106/mimosinnet/raku/ch-1.raku
@@ -0,0 +1,38 @@
+# https://perlweeklychallenge.org/blog/perl-weekly-challenge-106/
+
+multi sub challenge( @n where @n.elems == 1) { return 0 }
+multi sub challenge( @n ) {
+ return @n.sort.rotor( 2 => -1).map( -> ($a, $b) { $b - $a }).max;
+}
+
+multi sub MAIN( @n ) {
+ say 'Input: ',@n;
+ say 'Output: ',challenge(@n),"\n";
+}
+
+multi sub MAIN( 'challenge' ) {
+ my @challenge = (
+ (2, 9, 3, 5) ,
+ (1, 3, 8, 2, 0),
+ (5,)
+ );
+
+ for @challenge -> @a {
+ MAIN(@a);
+ }
+}
+
+multi sub MAIN( 'test' ) is hidden-from-USAGE {
+ use Test;
+
+ my @test = (
+ ( (2, 9, 3, 5) , 4,'Example 1' ),
+ ( (1, 3, 8, 2, 0), 5,'Example 2' ),
+ ( (5,) , 0,'Example 3' )
+ );
+
+ for @test -> (@a, $b, $c) {
+ is challenge(@a),$b,$c;
+ }
+
+}
diff --git a/challenge-106/mimosinnet/raku/ch-2.raku b/challenge-106/mimosinnet/raku/ch-2.raku
new file mode 100644
index 0000000000..21c650ec61
--- /dev/null
+++ b/challenge-106/mimosinnet/raku/ch-2.raku
@@ -0,0 +1,40 @@
+# https://perlweeklychallenge.org/blog/perl-weekly-challenge-106/
+
+# see: https://docs.raku.org/routine/base-repeating
+sub challenge( $a, $b ) {
+ my ($non-rep, $repeating) = ( $a / $b).base-repeating;
+ return $non-rep if $repeating eq '';
+ return "$non-rep\($repeating\)";
+}
+
+multi sub MAIN( $n, $d ) {
+ say 'Input: $N = ',$n,', $D = ',$d;
+ say 'Output: "',challenge($n,$d),"\"\n";
+}
+
+multi sub MAIN( 'challenge' ) {
+ my @challenge = (
+ (1, 3),
+ (1, 2),
+ (5, 66)
+ );
+
+ for @challenge -> ($a, $b) {
+ MAIN($a,$b);
+ }
+}
+
+multi sub MAIN( 'test' ) is hidden-from-USAGE {
+ use Test;
+
+ my @test = (
+ (1, 3, '0.(3)' ),
+ (1, 2, '0.5' ),
+ (5, 66, '0.0(75)')
+ );
+
+ for @test -> ($a, $b, $c ) {
+ is challenge($a,$b), $c;
+ }
+
+}