aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaulo Custodio <pauloscustodio@gmail.com>2023-03-09 18:01:58 +0000
committerPaulo Custodio <pauloscustodio@gmail.com>2023-03-09 18:01:58 +0000
commite2b3a9b9cbd927d33516c42b88ec16bf0aebcb58 (patch)
tree598bad7416234afb8b5a8fd368c8ba4b1abff3ac
parent502fa7462f63b6442cf4c00322278386bb525f9f (diff)
downloadperlweeklychallenge-club-e2b3a9b9cbd927d33516c42b88ec16bf0aebcb58.tar.gz
perlweeklychallenge-club-e2b3a9b9cbd927d33516c42b88ec16bf0aebcb58.tar.bz2
perlweeklychallenge-club-e2b3a9b9cbd927d33516c42b88ec16bf0aebcb58.zip
Add Perl solution
-rw-r--r--challenge-201/paulo-custodio/Makefile2
-rw-r--r--challenge-201/paulo-custodio/perl/ch-1.pl33
-rw-r--r--challenge-201/paulo-custodio/perl/ch-2.pl56
-rw-r--r--challenge-201/paulo-custodio/t/test-1.yaml10
-rw-r--r--challenge-201/paulo-custodio/t/test-2.yaml5
5 files changed, 106 insertions, 0 deletions
diff --git a/challenge-201/paulo-custodio/Makefile b/challenge-201/paulo-custodio/Makefile
new file mode 100644
index 0000000000..c3c762d746
--- /dev/null
+++ b/challenge-201/paulo-custodio/Makefile
@@ -0,0 +1,2 @@
+all:
+ perl ../../challenge-001/paulo-custodio/test.pl
diff --git a/challenge-201/paulo-custodio/perl/ch-1.pl b/challenge-201/paulo-custodio/perl/ch-1.pl
new file mode 100644
index 0000000000..9e463d4072
--- /dev/null
+++ b/challenge-201/paulo-custodio/perl/ch-1.pl
@@ -0,0 +1,33 @@
+#!/usr/bin/perl
+
+# Challenge 201
+#
+# Task 1: Missing Numbers
+# Submitted by: Mohammad S Anwar
+#
+# You are given an array of unique numbers.
+#
+# Write a script to find out all missing numbers in the range 0..$n where $n
+# is the array size.
+#
+# Example 1
+#
+# Input: @array = (0,1,3)
+# Output: 2
+#
+# The array size i.e. total element count is 3, so the range is 0..3.
+# The missing number is 2 in the given array.
+#
+# Example 2
+#
+# Input: @array = (0,1)
+# Output: 2
+#
+# The array size is 2, therefore the range is 0..2.
+# The missing number is 2.
+
+use Modern::Perl;
+
+my @in = @ARGV;
+my %in; $in{$_}=1 for @in;
+say join(" ", grep {!$in{$_}} 0..@in);
diff --git a/challenge-201/paulo-custodio/perl/ch-2.pl b/challenge-201/paulo-custodio/perl/ch-2.pl
new file mode 100644
index 0000000000..e4e9fef4b8
--- /dev/null
+++ b/challenge-201/paulo-custodio/perl/ch-2.pl
@@ -0,0 +1,56 @@
+#!/usr/bin/perl
+
+# Challenge 201
+#
+# Task 2: Penny Piles
+# Submitted by: Robbie Hatley
+#
+# You are given an integer, $n > 0.
+#
+# Write a script to determine the number of ways of putting $n pennies in a row
+# of piles of ascending heights from left to right.
+# Example
+#
+# Input: $n = 5
+# Output: 7
+#
+# Since $n=5, there are 7 ways of stacking 5 pennies in ascending piles:
+#
+# 1 1 1 1 1
+# 1 1 1 2
+# 1 2 2
+# 1 1 3
+# 2 3
+# 1 4
+# 5
+
+use Modern::Perl;
+no warnings 'recursion';
+
+sub make_piles1 {
+ my($count, $prev, $n) = @_;
+ my @prev = @$prev;
+ if ($n < 0) {
+ }
+ elsif ($n == 0) {
+ #say "@prev";
+ $$count++;
+ }
+ else {
+ my $max = @prev==0 ? $n : $prev[-1];
+ for my $i (1..$max) {
+ make_piles1($count, [@prev, $i], $n-$i);
+ }
+ }
+}
+
+sub make_piles {
+ my($n) = @_;
+ my $count = 0;
+ make_piles1(\$count, [], $n);
+ return $count;
+}
+
+@ARGV==1 or die "usage: ch-2.pl n\n";
+my($n) = @ARGV;
+say make_piles($n);
diff --git a/challenge-201/paulo-custodio/t/test-1.yaml b/challenge-201/paulo-custodio/t/test-1.yaml
new file mode 100644
index 0000000000..ddb6cf1c40
--- /dev/null
+++ b/challenge-201/paulo-custodio/t/test-1.yaml
@@ -0,0 +1,10 @@
+- setup:
+ cleanup:
+ args: 0 1 3
+ input:
+ output: 2
+- setup:
+ cleanup:
+ args: 0 1
+ input:
+ output: 2
diff --git a/challenge-201/paulo-custodio/t/test-2.yaml b/challenge-201/paulo-custodio/t/test-2.yaml
new file mode 100644
index 0000000000..ed3c8af885
--- /dev/null
+++ b/challenge-201/paulo-custodio/t/test-2.yaml
@@ -0,0 +1,5 @@
+- setup:
+ cleanup:
+ args: 5
+ input:
+ output: 7