aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad Sajid Anwar <Mohammad.Anwar@yahoo.com>2024-09-02 22:05:37 +0100
committerGitHub <noreply@github.com>2024-09-02 22:05:37 +0100
commit94a85756a38dfc0ef9538b85712345b848e0b780 (patch)
tree7434b076369cf45dd3132c96b0abc17368ba2f75
parent5883b19354bd9a8cff497991eb2e276076c7df54 (diff)
parent889d54e9da3132ac4eb3eea9bdbb36b5fe3e423b (diff)
downloadperlweeklychallenge-club-94a85756a38dfc0ef9538b85712345b848e0b780.tar.gz
perlweeklychallenge-club-94a85756a38dfc0ef9538b85712345b848e0b780.tar.bz2
perlweeklychallenge-club-94a85756a38dfc0ef9538b85712345b848e0b780.zip
Merge pull request #10760 from wlmb/challenges
Solve PWC 285
-rw-r--r--challenge-285/wlmb/blog.txt1
-rwxr-xr-xchallenge-285/wlmb/perl/ch-1.pl18
-rwxr-xr-xchallenge-285/wlmb/perl/ch-2.pl26
3 files changed, 45 insertions, 0 deletions
diff --git a/challenge-285/wlmb/blog.txt b/challenge-285/wlmb/blog.txt
new file mode 100644
index 0000000000..951aa5de7d
--- /dev/null
+++ b/challenge-285/wlmb/blog.txt
@@ -0,0 +1 @@
+https://wlmb.github.io/2024/09/02/PWC285/
diff --git a/challenge-285/wlmb/perl/ch-1.pl b/challenge-285/wlmb/perl/ch-1.pl
new file mode 100755
index 0000000000..f1421e4b37
--- /dev/null
+++ b/challenge-285/wlmb/perl/ch-1.pl
@@ -0,0 +1,18 @@
+#!/usr/bin/env perl
+# Perl weekly challenge 285
+# Task 1: No Connection
+#
+# See https://wlmb.github.io/2024/09/02/PWC285/#task-1-no-connection
+use v5.36;
+use experimental qw(for_list);
+die <<~"FIN" unless @ARGV and @ARGV%2==0;
+ Usage: $0 I1 O1 I2 O2...
+ where Ii is the incoming and Oi the outgoing node
+ of the i-th edge.
+ FIN
+my (%in, %out);
+for my($in,$out)(@ARGV){
+ ++$in{$in} if $in ne $out;
+ ++$out{$out};
+}
+say "@ARGV -> ", join " ", grep{!$in{$_}}keys %out;
diff --git a/challenge-285/wlmb/perl/ch-2.pl b/challenge-285/wlmb/perl/ch-2.pl
new file mode 100755
index 0000000000..9e62d1d808
--- /dev/null
+++ b/challenge-285/wlmb/perl/ch-2.pl
@@ -0,0 +1,26 @@
+#!/usr/bin/env perl
+# Perl weekly challenge 285
+# Task 2: Making Change
+#
+# See https://wlmb.github.io/2024/09/02/PWC285/#task-2-making-change
+use v5.36;
+use Memoize;
+die <<~"FIN" unless @ARGV;
+ Usage: $0 A1 A2...
+ to find in how many ways can the amounts Ai can be
+ formed with coins (pennies, nickels, dimes, quartes
+ and half-dollars)
+ FIN
+memoize qw(number_of_ways);
+my @values=(1,5,10,25,50); # sorted
+my $large=1+$values[-1]; # larger than largest coin
+for(@ARGV){
+ say "$_ -> ",number_of_ways($_+$large, $large)
+}
+sub number_of_ways($amount,$first_coin){
+ return 0 if $first_coin>$amount;
+ return 1 if $first_coin==$amount;
+ my $total;
+ $total+=number_of_ways($amount-$first_coin, $_)for grep{$_<=$first_coin}@values;
+ return $total;
+}