diff options
| author | Mark Anderson <mark@andemark.io> | 2024-09-02 03:27:59 +0000 |
|---|---|---|
| committer | Mark Anderson <mark@andemark.io> | 2024-09-02 03:27:59 +0000 |
| commit | c56ed0a6a4830cecd99b6d871783cab00d721d92 (patch) | |
| tree | 8797c4e183ae5e9491af49c577d35b4d77fc6c7b | |
| parent | 0512711fccf91c731495f1dd901349cc900ec299 (diff) | |
| download | perlweeklychallenge-club-c56ed0a6a4830cecd99b6d871783cab00d721d92.tar.gz perlweeklychallenge-club-c56ed0a6a4830cecd99b6d871783cab00d721d92.tar.bz2 perlweeklychallenge-club-c56ed0a6a4830cecd99b6d871783cab00d721d92.zip | |
Challenge 285 Solutions (Raku)
| -rw-r--r-- | challenge-285/mark-anderson/raku/ch-1.raku | 10 | ||||
| -rw-r--r-- | challenge-285/mark-anderson/raku/ch-2.raku | 45 |
2 files changed, 55 insertions, 0 deletions
diff --git a/challenge-285/mark-anderson/raku/ch-1.raku b/challenge-285/mark-anderson/raku/ch-1.raku new file mode 100644 index 0000000000..b85039083a --- /dev/null +++ b/challenge-285/mark-anderson/raku/ch-1.raku @@ -0,0 +1,10 @@ +#!/usr/bin/env raku +use Test; + +is no-connection((<B C>, <D B>, <C A>)), 'A'; +is no-connection((<A Z>,)), 'Z'; + +sub no-connection($routes) +{ + $routes>>[1] (-) $routes>>[0] +} diff --git a/challenge-285/mark-anderson/raku/ch-2.raku b/challenge-285/mark-anderson/raku/ch-2.raku new file mode 100644 index 0000000000..01b60b4708 --- /dev/null +++ b/challenge-285/mark-anderson/raku/ch-2.raku @@ -0,0 +1,45 @@ +#!/usr/bin/env raku +use Test; + +is making-change(9), 2; +is making-change(15), 6; +is making-change(100), 292; + +is making-change-polymod(9), 2; +is making-change-polymod(15), 6; +is making-change-polymod(100), 292; + +sub making-change($amount) +{ + .elems given gather loop (my $n = 0; $n <= $amount; $n += 5) + { + loop (my $d = 0; $d <= $amount; $d += 10) + { + last if $n + $d > $amount; + + loop (my $q = 0; $q <= $amount; $q += 25) + { + last if $d + $q > $amount; + last if $n + $d + $q > $amount; + + loop (my $h = 0; $h <= $amount; $h += 50) + { + last if $q + $h > $amount; + last if $d + $q + $h > $amount; + last if $n + $d + $q + $h > $amount; + .take + } + } + } + } +} + +# This sub is like the one above without the short circuiting. +sub making-change-polymod($amount) +{ + 1 + .elems given do for 1..3464 + { + my $p = .polymod(21,11,5,3).List; + $p if ([+] $p.head(4) Z* (5,10,25,50)) <= $amount + } +} |
