diff options
| -rw-r--r-- | challenge-156/lubos-kolouch/perl/ch-1.pl | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/challenge-156/lubos-kolouch/perl/ch-1.pl b/challenge-156/lubos-kolouch/perl/ch-1.pl new file mode 100644 index 0000000000..006fca6132 --- /dev/null +++ b/challenge-156/lubos-kolouch/perl/ch-1.pl @@ -0,0 +1,23 @@ +use strict; +use warnings; +use Math::Prime::Util qw/is_prime/; + +sub get_pernicious { + my $what = shift; + + my @nums; + + my $num = 0; + while ( scalar @nums < $what ) { + $num++; + my $bin_num = sprintf( "%b", $num ); + $bin_num =~ s/0//g; + push @nums, $num if is_prime( length($bin_num) ); + } + + return \@nums; +} + +use Test::More; +is_deeply( get_pernicious(10), [ 3, 5, 6, 7, 9, 10, 11, 12, 13, 14 ] ); +done_testing; |
