diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2021-05-23 16:54:04 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-05-23 16:54:04 +0100 |
| commit | d5e46349e47cea9a3c59c5c9cafc4e6babf97955 (patch) | |
| tree | 33bc6afb8e2e2be1ac1ca8f4d5740d936dced0bf /challenge-113 | |
| parent | bc39d8a1516079ad1492e16b3be7e0763dae85f5 (diff) | |
| parent | 01b4461c43222c077e82558ed65fe237be439e66 (diff) | |
| download | perlweeklychallenge-club-d5e46349e47cea9a3c59c5c9cafc4e6babf97955.tar.gz perlweeklychallenge-club-d5e46349e47cea9a3c59c5c9cafc4e6babf97955.tar.bz2 perlweeklychallenge-club-d5e46349e47cea9a3c59c5c9cafc4e6babf97955.zip | |
Merge pull request #4122 from mimosinnet/branch-for-challenge-113
Solutions for challenge 113
Diffstat (limited to 'challenge-113')
| -rw-r--r-- | challenge-113/mimosinnet/raku/ch-1.raku | 25 | ||||
| -rw-r--r-- | challenge-113/mimosinnet/raku/ch-2.raku | 66 |
2 files changed, 91 insertions, 0 deletions
diff --git a/challenge-113/mimosinnet/raku/ch-1.raku b/challenge-113/mimosinnet/raku/ch-1.raku new file mode 100644 index 0000000000..9c0a4bff7e --- /dev/null +++ b/challenge-113/mimosinnet/raku/ch-1.raku @@ -0,0 +1,25 @@ +# https://perlweeklychallenge.org/blog/perl-weekly-challenge-113/ + +#| +sub challenge( $n, $d ) { + return (1..$n).grep( /$d/ ).combinations(1..*).map({ $_.sum }).grep($n).Bool.Int; +} + +multi sub MAIN( $n where $n>0, $d where 1..9 ) { + say sprintf('Input: $N = %d, $D = %d',$n,$d); + say sprintf("Output: %d\n",challenge($n,$d)); +} + +multi sub MAIN( 'challenge' ) { + MAIN(25,7); + MAIN(24,7) +} + +multi sub MAIN( 'test' ) is hidden-from-USAGE { + use Test; + + is challenge(25,7),0; + is challenge(24,7),1; + + done-testing; +} diff --git a/challenge-113/mimosinnet/raku/ch-2.raku b/challenge-113/mimosinnet/raku/ch-2.raku new file mode 100644 index 0000000000..8d7997b211 --- /dev/null +++ b/challenge-113/mimosinnet/raku/ch-2.raku @@ -0,0 +1,66 @@ +# https://perlweeklychallenge.org/blog/perl-weekly-challenge-113/ + +sub challenge( @tree_input ) { + my $sum_nodes = @tree_input».List.flat.sum; + return @tree_input.deepmap( $sum_nodes - *); +} + +multi sub MAIN( @tree_input ) { + say 'Input Binary Tree ',@tree_input; + say 'Output Binary Tree ',challenge(@tree_input); +} + +multi sub MAIN( 'challenge' ) { + + my @tree_input = + (1, + (2, + (4, + (), + (7) + ), + ), + (3, + (5), + (6) + ) + ); + MAIN(@tree_input); +} + +multi sub MAIN( 'test' ) is hidden-from-USAGE { + use Test; + + my @tree_input = + (1, + (2, + (4, + (), + (7) + ), + ), + (3, + (5), + (6) + ) + ); + + my @tree_output = + (27, + (26, + (24, + (), + (21) + ) + ), + (25, + (23), + (22) + ) + ); + + is challenge(@tree_input),@tree_output; + + done-testing; + +} |
