line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
1
|
|
|
1
|
|
2545
|
use v5.24; |
|
1
|
|
|
|
|
3
|
|
2
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
28
|
|
3
|
1
|
|
|
1
|
|
4
|
use Test::More; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
19
|
|
4
|
1
|
|
|
1
|
|
247
|
use Q::S::L qw(superpos every_state); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
185
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
sub is_prime |
7
|
|
|
|
|
|
|
{ |
8
|
3
|
|
|
3
|
|
6
|
my ($number) = @_; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
# produce all the possible factors up to square root |
11
|
3
|
|
|
|
|
970
|
my $possible_factors = superpos(2 .. sqrt $number); |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
# for every state, check that there's no division remainder |
14
|
3
|
|
|
3
|
|
27522
|
return every_state { ($number % $possible_factors) != 0 }; |
|
3
|
|
|
|
|
20
|
|
15
|
|
|
|
|
|
|
} |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
my %numbers = ( |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
# number => is_prime? |
20
|
|
|
|
|
|
|
78 => 0, |
21
|
|
|
|
|
|
|
79 => 1, |
22
|
|
|
|
|
|
|
236116321 => 0, |
23
|
|
|
|
|
|
|
); |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
while (my ($number, $is_prime) = each %numbers) { |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
my $prime = is_prime $number; |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
# did we succeed? |
30
|
|
|
|
|
|
|
is $prime, !!$is_prime, "$number result ok - " . ($is_prime ? "is" : "isnt") . " prime"; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
done_testing; |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
__END__ |