diff options
| -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 + } +} |
