diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2021-12-05 20:41:02 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-12-05 20:41:02 +0000 |
| commit | 8e0e31cdc9b6c5776c63085b1f4f9503dd118b62 (patch) | |
| tree | c32b80bdd2bc0c57a253f2f1c84ed969429b9434 | |
| parent | 8230f354a7f3507ce840b5e70eed307c5ea81043 (diff) | |
| parent | 755ec272ffa233695c6650357e294c506362b3ed (diff) | |
| download | perlweeklychallenge-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.pl | 21 | ||||
| -rw-r--r-- | challenge-141/lubos-kolouch/perl/ch-2.pl | 33 |
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; |
