aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2021-12-05 20:41:02 +0000
committerGitHub <noreply@github.com>2021-12-05 20:41:02 +0000
commit8e0e31cdc9b6c5776c63085b1f4f9503dd118b62 (patch)
treec32b80bdd2bc0c57a253f2f1c84ed969429b9434
parent8230f354a7f3507ce840b5e70eed307c5ea81043 (diff)
parent755ec272ffa233695c6650357e294c506362b3ed (diff)
downloadperlweeklychallenge-club-8e0e31cdc9b6c5776c63085b1f4f9503dd118b62.tar.gz
perlweeklychallenge-club-8e0e31cdc9b6c5776c63085b1f4f9503dd118b62.tar.bz2
perlweeklychallenge-club-8e0e31cdc9b6c5776c63085b1f4f9503dd118b62.zip
Merge pull request #5332 from LubosKolouch/master
Challenge 141 LK Perl Task 1 2
-rw-r--r--challenge-141/lubos-kolouch/perl/ch-1.pl21
-rw-r--r--challenge-141/lubos-kolouch/perl/ch-2.pl33
2 files changed, 54 insertions, 0 deletions
diff --git a/challenge-141/lubos-kolouch/perl/ch-1.pl b/challenge-141/lubos-kolouch/perl/ch-1.pl
new file mode 100644
index 0000000000..c5598a84da
--- /dev/null
+++ b/challenge-141/lubos-kolouch/perl/ch-1.pl
@@ -0,0 +1,21 @@
+use strict;
+use warnings;
+use Data::Dumper;
+
+use Math::Factor::XS qw/factors/;
+
+my @nums;
+
+my $pos = 1;
+
+while ( scalar @nums < 10 ) {
+
+ my @factors = factors($pos);
+
+ # 1 and the number are always divisors
+ push @nums, $pos if scalar @factors == 6;
+
+ $pos++;
+}
+
+warn Dumper \@nums;
diff --git a/challenge-141/lubos-kolouch/perl/ch-2.pl b/challenge-141/lubos-kolouch/perl/ch-2.pl
new file mode 100644
index 0000000000..947a18b44b
--- /dev/null
+++ b/challenge-141/lubos-kolouch/perl/ch-2.pl
@@ -0,0 +1,33 @@
+use strict;
+use warnings;
+
+use Algorithm::Combinatorics qw/combinations/;
+use List::MoreUtils qw(uniq);
+
+sub get_integers {
+ my ( $what, $divisor ) = @_;
+
+ my @unique = uniq split '', $what;
+
+ my $result;
+
+ for my $i ( 1 .. scalar @unique - 1 ) {
+ my @combinations = combinations( \@unique, $i );
+
+ for my $comb (@combinations) {
+ my $num = join '', @$comb;
+ $result++ if $num % $divisor == 0;
+ }
+
+ }
+
+ return $result;
+
+}
+
+use Test::More;
+
+is( get_integers( 1234, 2 ), 9 );
+is( get_integers( 768, 4 ), 3 );
+
+done_testing;