diff options
| author | Mohammad Sajid Anwar <Mohammad.Anwar@yahoo.com> | 2024-09-02 12:59:48 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-09-02 12:59:48 +0100 |
| commit | 64bbef614212f020640061de7785a6550d2d4985 (patch) | |
| tree | aa3ee7ab156597372ab4339e69e5abbb952f8cab /challenge-285 | |
| parent | 4b1851dda8bcec1c9f4adb5fb9eda12e071baedc (diff) | |
| parent | c56ed0a6a4830cecd99b6d871783cab00d721d92 (diff) | |
| download | perlweeklychallenge-club-64bbef614212f020640061de7785a6550d2d4985.tar.gz perlweeklychallenge-club-64bbef614212f020640061de7785a6550d2d4985.tar.bz2 perlweeklychallenge-club-64bbef614212f020640061de7785a6550d2d4985.zip | |
Merge pull request #10753 from andemark/challenge-285
Challenge 285 Solutions (Raku)
Diffstat (limited to 'challenge-285')
| -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 + } +} |
