aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad Sajid Anwar <Mohammad.Anwar@yahoo.com>2024-09-02 13:01:22 +0100
committerGitHub <noreply@github.com>2024-09-02 13:01:22 +0100
commit15aabf08869eba6262eb088c845e27852440ecfe (patch)
treec4eae3bb204c2e6a20ababa3730b0e71503b2ca9
parent9ed7b68c35504643a459bdf688ef3268b42a6edd (diff)
parent0fe2bbe378645f016dba96d5c477f03f230c453f (diff)
downloadperlweeklychallenge-club-15aabf08869eba6262eb088c845e27852440ecfe.tar.gz
perlweeklychallenge-club-15aabf08869eba6262eb088c845e27852440ecfe.tar.bz2
perlweeklychallenge-club-15aabf08869eba6262eb088c845e27852440ecfe.zip
Merge pull request #10756 from seaker/master
challenge 285, raku solutions
-rwxr-xr-xchallenge-284/feng-chang/raku/ch-2.raku6
-rwxr-xr-xchallenge-285/feng-chang/raku/ch-1.raku6
-rwxr-xr-xchallenge-285/feng-chang/raku/ch-2.raku13
-rwxr-xr-xchallenge-285/feng-chang/raku/test.raku23
4 files changed, 44 insertions, 4 deletions
diff --git a/challenge-284/feng-chang/raku/ch-2.raku b/challenge-284/feng-chang/raku/ch-2.raku
index 25a4be73c5..aa6f179bf5 100755
--- a/challenge-284/feng-chang/raku/ch-2.raku
+++ b/challenge-284/feng-chang/raku/ch-2.raku
@@ -3,12 +3,10 @@
unit sub MAIN(Str:D $L1, Str:D $L2);
my %pos = $L2.comb(/\d+/).map({ $_ => $++ });
-
my (@list3, @list4);
for $L1.comb(/\d+/) -> $n {
- %pos{$n}.defined ??
- @list3[%pos{$n}].push($n) !!
- @list4.push($n);
+ with %pos{$n} { @list3[$_].push($n); }
+ else { @list4.push($n); }
}
put (|@list3[*;*], |@list4.sort).join(',');
diff --git a/challenge-285/feng-chang/raku/ch-1.raku b/challenge-285/feng-chang/raku/ch-1.raku
new file mode 100755
index 0000000000..a60e8f5475
--- /dev/null
+++ b/challenge-285/feng-chang/raku/ch-1.raku
@@ -0,0 +1,6 @@
+#!/bin/env raku
+
+unit sub MAIN(Str:D $r);
+
+my %routes = $r.comb.rotor(2).map({ .[0] => .[1] });
+put %routes.values.grep({ !%routes{$_}.defined }).first;
diff --git a/challenge-285/feng-chang/raku/ch-2.raku b/challenge-285/feng-chang/raku/ch-2.raku
new file mode 100755
index 0000000000..3670056183
--- /dev/null
+++ b/challenge-285/feng-chang/raku/ch-2.raku
@@ -0,0 +1,13 @@
+#!/bin/env raku
+
+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(\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 }
+multi changes(\a, 5) { (0..a div 5).map({ changes(a - $_ * 5, 1) }).sum }
+
+put changes(amount, 50);
diff --git a/challenge-285/feng-chang/raku/test.raku b/challenge-285/feng-chang/raku/test.raku
new file mode 100755
index 0000000000..61705811a5
--- /dev/null
+++ b/challenge-285/feng-chang/raku/test.raku
@@ -0,0 +1,23 @@
+#!/bin/env raku
+
+# The Weekly Challenge 285
+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 1, No Connection
+pwc-test './ch-1.raku', 'BCDBCA', 'A', 'No Connection: B=>C,D=>B,C=>A => A';
+pwc-test './ch-1.raku', 'AZ', 'Z', 'No Connection: A=>Z => Z';
+
+# Task 2, Maing Change
+pwc-test './ch-2.raku', 9, 2, 'Maing Change: 9 => 2';
+pwc-test './ch-2.raku', 15, 6, 'Maing Change: 15 => 6';
+pwc-test './ch-2.raku', 100, 292, 'Maing Change: 100 => 292';