aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaulo Custodio <pauloscustodio@gmail.com>2021-12-06 16:07:55 +0000
committerPaulo Custodio <pauloscustodio@gmail.com>2021-12-06 16:08:58 +0000
commit0738a0e639d7b7e8f60cf0ecd60d2f5e6f8124b7 (patch)
tree8af5982a927ef466df5a4a286cd24aeef59fcb0a
parentcd04687f29d4ebea2fd5ec165585b21f2951f413 (diff)
downloadperlweeklychallenge-club-0738a0e639d7b7e8f60cf0ecd60d2f5e6f8124b7.tar.gz
perlweeklychallenge-club-0738a0e639d7b7e8f60cf0ecd60d2f5e6f8124b7.tar.bz2
perlweeklychallenge-club-0738a0e639d7b7e8f60cf0ecd60d2f5e6f8124b7.zip
Add Perl solution to challenge 142
-rw-r--r--challenge-142/paulo-custodio/perl/ch-1.pl41
-rw-r--r--challenge-142/paulo-custodio/perl/ch-2.pl24
-rw-r--r--challenge-142/paulo-custodio/t/test-1.yaml10
-rw-r--r--challenge-142/paulo-custodio/t/test-2.yaml14
4 files changed, 89 insertions, 0 deletions
diff --git a/challenge-142/paulo-custodio/perl/ch-1.pl b/challenge-142/paulo-custodio/perl/ch-1.pl
new file mode 100644
index 0000000000..76a8e19638
--- /dev/null
+++ b/challenge-142/paulo-custodio/perl/ch-1.pl
@@ -0,0 +1,41 @@
+#!/usr/bin/perl
+
+# TASK #1 > Divisor Last Digit
+# Submitted by: Mohammad S Anwar
+# You are given positive integers, $m and $n.
+#
+# Write a script to find total count of divisors of $m having last digit $n.
+#
+#
+# Example 1:
+# Input: $m = 24, $n = 2
+# Output: 2
+#
+# The divisors of 24 are 1, 2, 3, 4, 6, 8 and 12.
+# There are only 2 divisors having last digit 2 are 2 and 12.
+#
+# Example 2:
+# Input: $m = 30, $n = 5
+# Output: 2
+#
+# The divisors of 30 are 1, 2, 3, 5, 6, 10 and 15.
+# There are only 2 divisors having last digit 5 are 5 and 15.
+
+use Modern::Perl;
+
+sub divisors {
+ my($n) = @_;
+ my(@div_low, @div_high);
+ for (my $i = 1; $i <= sqrt($n); $i++) {
+ if ($n%$i == 0) {
+ push @div_low, $i;
+ unshift @div_high, $n/$i if $n/$i != $i;
+ }
+ }
+ return (@div_low, @div_high);
+}
+
+my($m, $n) = @ARGV;
+my @divisors = divisors($m);
+my $count = scalar grep {/$n$/} @divisors;
+say $count;
diff --git a/challenge-142/paulo-custodio/perl/ch-2.pl b/challenge-142/paulo-custodio/perl/ch-2.pl
new file mode 100644
index 0000000000..83160b0a28
--- /dev/null
+++ b/challenge-142/paulo-custodio/perl/ch-2.pl
@@ -0,0 +1,24 @@
+#!/usr/bin/perl
+
+# TASK #2 > Sleep Sort
+# Submitted by: Adam Russell
+# Another joke sort similar to JortSort suggested by champion Adam Russell.
+#
+# You are given a list of numbers.
+#
+# Write a script to implement Sleep Sort. For more information, please checkout
+# this post.
+
+use Modern::Perl;
+use Config;
+use threads;
+
+sub sleeper {
+ my($n) = @_;
+ sleep $n;
+ say $n;
+}
+
+my @thrs;
+push @thrs, threads->create(\&sleeper, $_) for @ARGV;
+$_->join() for @thrs;
diff --git a/challenge-142/paulo-custodio/t/test-1.yaml b/challenge-142/paulo-custodio/t/test-1.yaml
new file mode 100644
index 0000000000..73afb6c3bd
--- /dev/null
+++ b/challenge-142/paulo-custodio/t/test-1.yaml
@@ -0,0 +1,10 @@
+- setup:
+ cleanup:
+ args: 24 2
+ input:
+ output: 2
+- setup:
+ cleanup:
+ args: 30 5
+ input:
+ output: 2
diff --git a/challenge-142/paulo-custodio/t/test-2.yaml b/challenge-142/paulo-custodio/t/test-2.yaml
new file mode 100644
index 0000000000..5880ec1526
--- /dev/null
+++ b/challenge-142/paulo-custodio/t/test-2.yaml
@@ -0,0 +1,14 @@
+- setup:
+ cleanup:
+ args: 1 9 3 2 8 6 7 5 4
+ input:
+ output: |
+ 1
+ 2
+ 3
+ 4
+ 5
+ 6
+ 7
+ 8
+ 9