diff options
| author | Lubos Kolouch <lubos@kolouch.net> | 2021-12-05 20:15:43 +0100 |
|---|---|---|
| committer | Lubos Kolouch <lubos@kolouch.net> | 2021-12-05 20:15:43 +0100 |
| commit | 755ec272ffa233695c6650357e294c506362b3ed (patch) | |
| tree | e85b15d9c5807967e7753240b85da1934ec59484 | |
| parent | 08cb7f5a40310234e72534e9e2f9d9b97b8a0694 (diff) | |
| download | perlweeklychallenge-club-755ec272ffa233695c6650357e294c506362b3ed.tar.gz perlweeklychallenge-club-755ec272ffa233695c6650357e294c506362b3ed.tar.bz2 perlweeklychallenge-club-755ec272ffa233695c6650357e294c506362b3ed.zip | |
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; |
