diff options
| -rw-r--r-- | challenge-142/paulo-custodio/perl/ch-1.pl | 41 | ||||
| -rw-r--r-- | challenge-142/paulo-custodio/perl/ch-2.pl | 24 | ||||
| -rw-r--r-- | challenge-142/paulo-custodio/t/test-1.yaml | 10 | ||||
| -rw-r--r-- | challenge-142/paulo-custodio/t/test-2.yaml | 14 |
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 |
