diff options
| author | Lubos Kolouch <lubos@kolouch.net> | 2022-03-18 21:07:49 +0100 |
|---|---|---|
| committer | Lubos Kolouch <lubos@kolouch.net> | 2022-03-18 21:07:49 +0100 |
| commit | 44dee40a00e0f597c3a62e791549220d2e1d262e (patch) | |
| tree | 6fcbfeaa0e55f584f270b119f149abb0174a5710 | |
| parent | e8a0fa0eef190dafa38204a37e41e16df4416b39 (diff) | |
| download | perlweeklychallenge-club-44dee40a00e0f597c3a62e791549220d2e1d262e.tar.gz perlweeklychallenge-club-44dee40a00e0f597c3a62e791549220d2e1d262e.tar.bz2 perlweeklychallenge-club-44dee40a00e0f597c3a62e791549220d2e1d262e.zip | |
feat(challenge-156/lubos-kolouch/ch-2.pl): Challenge 156 Task 2 Perl LK
| -rw-r--r-- | challenge-156/lubos-kolouch/perl/ch-2.pl | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/challenge-156/lubos-kolouch/perl/ch-2.pl b/challenge-156/lubos-kolouch/perl/ch-2.pl new file mode 100644 index 0000000000..2880e67d04 --- /dev/null +++ b/challenge-156/lubos-kolouch/perl/ch-2.pl @@ -0,0 +1,30 @@ +use strict; +use warnings; +use List::Util qw/sum/; +use Math::Combinatorics; +use Math::Prime::Util qw/divisors/; + +sub is_weird { + my $what = shift; + + my @all_divisors = divisors($what); + + # remove the number itself from the list + pop @all_divisors; + + return 0 unless sum(@all_divisors) > $what; + + for my $i ( 1 .. scalar @all_divisors ) { + my $p = Math::Combinatorics->new( data => \@all_divisors, count => $i ); + while ( my @res = $p->next_combination ) { + return 0 if sum(@res) == $what; + } + } + return 1; +} + +use Test::More; +is( is_weird(12), 0 ); +is( is_weird(70), 1 ); + +done_testing; |
