aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2021-12-01 18:09:33 +0000
committerGitHub <noreply@github.com>2021-12-01 18:09:33 +0000
commitb8ba8a51399ad200692734198eed8b2fde1b1db0 (patch)
tree6e88c82ccc7460b2ec698c56c3fa90d22b7e7afc
parent693dda8774abdff0bf8f09abe8fd7d3eb7c066ec (diff)
parent0a494c3c02450c957127182b7b63d418cd1aaca6 (diff)
downloadperlweeklychallenge-club-b8ba8a51399ad200692734198eed8b2fde1b1db0.tar.gz
perlweeklychallenge-club-b8ba8a51399ad200692734198eed8b2fde1b1db0.tar.bz2
perlweeklychallenge-club-b8ba8a51399ad200692734198eed8b2fde1b1db0.zip
Merge pull request #5304 from PerlBoy1967/branch-for-challenge-141
Branch for challenge 141
-rwxr-xr-xchallenge-141/perlboy1967/perl/ch-1.pl49
-rwxr-xr-xchallenge-141/perlboy1967/perl/ch-2.pl53
2 files changed, 102 insertions, 0 deletions
diff --git a/challenge-141/perlboy1967/perl/ch-1.pl b/challenge-141/perlboy1967/perl/ch-1.pl
new file mode 100755
index 0000000000..9cb31d273f
--- /dev/null
+++ b/challenge-141/perlboy1967/perl/ch-1.pl
@@ -0,0 +1,49 @@
+#!/bin/perl
+
+=pod
+
+The Weekly Challenge - 141
+ - https://perlweeklychallenge.org/blog/perl-weekly-challenge-141/#TASK1
+
+Author: Niels 'PerlBoy' van Dijke
+
+TASK #1 › Number Divisors
+Submitted by: Mohammad S Anwar
+
+Write a script to find lowest 10 positive integers having exactly 8 divisors.
+
+=cut
+
+use v5.16;
+use strict;
+use warnings;
+
+use Data::Printer output => 'stdout';
+
+sub hasNDivisors($$);
+
+my $n = 24;
+my @n;
+
+while (scalar(@n) < 10) {
+ if (hasNDivisors($n,8)) {
+ push(@n,$n);
+ }
+ $n++;
+}
+
+p @n;
+
+
+sub hasNDivisors($$) {
+ my ($n,$count) = @_;
+
+ my $i = 1;
+ my @d = ($i);
+ while ($i < $n) {
+ push(@d,$i) if ($n % $i == 0);
+ $i++;
+ }
+
+ return (scalar(@d) == $count);
+}
diff --git a/challenge-141/perlboy1967/perl/ch-2.pl b/challenge-141/perlboy1967/perl/ch-2.pl
new file mode 100755
index 0000000000..51364c6f0b
--- /dev/null
+++ b/challenge-141/perlboy1967/perl/ch-2.pl
@@ -0,0 +1,53 @@
+#!/bin/perl
+
+=pod
+
+The Weekly Challenge - 141
+ - https://perlweeklychallenge.org/blog/perl-weekly-challenge-141/#TASK2
+
+Author: Niels 'PerlBoy' van Dijke
+
+TASK #2 › Like Numbers
+Submitted by: Mohammad S Anwar
+
+i You are given positive integers, $m and $n.
+
+Write a script to find total count of integers created using the digits of $m
+which is also divisible by $n.
+
+Repeating of digits are not allowed. Order/Sequence of digits can’t be
+altered. You are only allowed to use (n-1) digits at the most. For example,
+432 is not acceptable integer created using the digits of 1234. Also for 1234,
+you can only have integers having no more than three digits.
+
+=cut
+
+use v5.16;
+use strict;
+use warnings;
+
+use List::MoreUtils qw(uniq);
+use Algorithm::Combinatorics qw(combinations);
+
+sub likeNumbers($$);
+
+my @n = likeNumbers($ARGV[0],$ARGV[1]);
+printf "%d => (%s)\n", scalar(@n), join(',',@n);
+
+
+sub likeNumbers($$) {
+ my ($m,$n) = @_;
+
+ my @res;
+
+ my @digits = uniq split //,$m;
+ foreach my $len (1 .. scalar(@digits)) {
+ my $iter = combinations(\@digits,$len);
+ while (my $ar = $iter->next) {
+ my $val = join('',@$ar);
+ push(@res,$val) if ($val % $n == 0 and $val != $m);
+ }
+ }
+
+ return @res;
+}