diff options
| author | mimosinnet <mimosinnet@gmail.com> | 2021-04-04 19:38:01 +0200 |
|---|---|---|
| committer | mimosinnet <mimosinnet@gmail.com> | 2021-04-04 19:38:01 +0200 |
| commit | 3865c78aefff6f4ce248029aa0a4f69fe52ddbdf (patch) | |
| tree | 89ebe858d87658fd67b3915a314bedf10aeb025f | |
| parent | d5ff10db3ea3e9e6e150316af0d4e4c0e2a37fe1 (diff) | |
| download | perlweeklychallenge-club-3865c78aefff6f4ce248029aa0a4f69fe52ddbdf.tar.gz perlweeklychallenge-club-3865c78aefff6f4ce248029aa0a4f69fe52ddbdf.tar.bz2 perlweeklychallenge-club-3865c78aefff6f4ce248029aa0a4f69fe52ddbdf.zip | |
Solutions to challenge 106
| -rw-r--r-- | challenge-106/mimosinnet/raku/ch-1.raku | 38 | ||||
| -rw-r--r-- | challenge-106/mimosinnet/raku/ch-2.raku | 40 |
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; + } + +} |
