diff options
| author | Mohammad Sajid Anwar <Mohammad.Anwar@yahoo.com> | 2024-09-09 09:15:50 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-09-09 09:15:50 +0100 |
| commit | 9cc66c48b4582f86b948d3a2d7d14bedf803367c (patch) | |
| tree | 298eb7a7959af3ff040a86720db64101b5284e2d | |
| parent | 1e08f8c1a23ce5d257cfda49e75302f90ab256d9 (diff) | |
| parent | 54381bea9a395fb921918a383f242ec40c4fa32f (diff) | |
| download | perlweeklychallenge-club-9cc66c48b4582f86b948d3a2d7d14bedf803367c.tar.gz perlweeklychallenge-club-9cc66c48b4582f86b948d3a2d7d14bedf803367c.tar.bz2 perlweeklychallenge-club-9cc66c48b4582f86b948d3a2d7d14bedf803367c.zip | |
Merge pull request #10801 from seaker/master
challenge 286, raku solutions
| -rwxr-xr-x | challenge-285/feng-chang/raku/ch-2.raku | 4 | ||||
| -rwxr-xr-x | challenge-286/feng-chang/raku/ch-1.raku | 5 | ||||
| -rwxr-xr-x | challenge-286/feng-chang/raku/ch-2.raku | 12 | ||||
| -rwxr-xr-x | challenge-286/feng-chang/raku/test.raku | 19 |
4 files changed, 38 insertions, 2 deletions
diff --git a/challenge-285/feng-chang/raku/ch-2.raku b/challenge-285/feng-chang/raku/ch-2.raku index 3670056183..a14135e8aa 100755 --- a/challenge-285/feng-chang/raku/ch-2.raku +++ b/challenge-285/feng-chang/raku/ch-2.raku @@ -3,8 +3,8 @@ unit sub MAIN(UInt:D \amount); proto changes(UInt:D \amount, UInt:D \limit --> UInt:D) {*} -multi changes(0, $_) { 1 } -multi changes(\a, 1) { 1 } +multi changes(0, $) { 1 } +multi changes($, 1) { 1 } multi changes(\a, 50) { (0..a div 50).map({ changes(a - $_ * 50, 25) }).sum } multi changes(\a, 25) { (0..a div 25).map({ changes(a - $_ * 25, 10) }).sum } multi changes(\a, 10) { (0..a div 10).map({ changes(a - $_ * 10, 5) }).sum } diff --git a/challenge-286/feng-chang/raku/ch-1.raku b/challenge-286/feng-chang/raku/ch-1.raku new file mode 100755 index 0000000000..d5b63cebdc --- /dev/null +++ b/challenge-286/feng-chang/raku/ch-1.raku @@ -0,0 +1,5 @@ +#!/bin/env raku + +unit sub MAIN(); + +put $*PROGRAM-NAME.IO.words.pick; diff --git a/challenge-286/feng-chang/raku/ch-2.raku b/challenge-286/feng-chang/raku/ch-2.raku new file mode 100755 index 0000000000..75236a3b75 --- /dev/null +++ b/challenge-286/feng-chang/raku/ch-2.raku @@ -0,0 +1,12 @@ +#!/bin/env raku + +unit sub MAIN(*@ints); + +while +@ints > 1 { + my @ints_ = gather for @ints -> $a, $b { + take $++ %% 2 ?? min($a,$b) !! max($a,$b); + } + @ints = @ints_; +} + +put @ints[0]; diff --git a/challenge-286/feng-chang/raku/test.raku b/challenge-286/feng-chang/raku/test.raku new file mode 100755 index 0000000000..b5bc479734 --- /dev/null +++ b/challenge-286/feng-chang/raku/test.raku @@ -0,0 +1,19 @@ +#!/bin/env raku + +# The Weekly Challenge 286 +use Test; + +sub pwc-test(Str:D $script, Bool :$deeply? = False, *@input) { + my ($expect, $assertion) = @input.splice(*-2, 2); + my $p = run $script, |@input, :out; + if $deeply { + is-deeply $p.out.slurp(:close).chomp.words.Bag, $expect, $assertion; + } else { + is $p.out.slurp(:close).chomp, $expect, $assertion; + } +} + +# Task 2, Order Game +pwc-test './ch-2.raku', <2 1 4 5 6 3 0 2>, 1, 'Order Game: 2,1,4,5,6,3,0,2 => 1'; +pwc-test './ch-2.raku', <0 5 3 2>, 0, 'Order Game: 0,5,3,2 => 0'; +pwc-test './ch-2.raku', <9 2 1 4 5 6 0 7 3 1 3 5 7 9 0 8>, 2, 'Order Game: 9,2,1,4,5,6,0,7,3,1,3,5,7,9,0,8 => 2'; |
