line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
1
|
|
|
1
|
|
2734
|
use v5.24; |
|
1
|
|
|
|
|
2
|
|
2
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
31
|
|
3
|
1
|
|
|
1
|
|
4
|
use Test::More; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
6
|
|
4
|
1
|
|
|
1
|
|
218
|
use Q::S::L qw(superpos fetch_matches with_sources); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
290
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
sub power_sources |
7
|
|
|
|
|
|
|
{ |
8
|
4
|
|
|
4
|
|
10
|
my ($number) = @_; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
# produce all the possible bases end exponents |
11
|
4
|
|
|
|
|
35
|
my $possible_bases = superpos(2 .. sqrt $number); |
12
|
4
|
|
|
|
|
805
|
my $possible_exponents = superpos(2 .. sqrt $number); |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
# produce all possible powers |
15
|
4
|
|
|
|
|
808
|
my $possible_powers = $possible_bases**$possible_exponents; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
# for every state, get those that match a condition |
18
|
|
|
|
|
|
|
# (any possible power that equals the number) |
19
|
|
|
|
|
|
|
return fetch_matches { |
20
|
4
|
|
|
|
|
17
|
with_sources { $possible_powers == $number } |
21
|
4
|
|
|
4
|
|
837
|
}; |
|
4
|
|
|
|
|
23
|
|
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
my %numbers = ( |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
# number => [base, exponent] |
27
|
|
|
|
|
|
|
65536 => [[2, 16], [4, 8], [16, 4], [256, 2]], |
28
|
|
|
|
|
|
|
9 => [[3, 2]], |
29
|
|
|
|
|
|
|
81 => [[3, 4], [9, 2]], |
30
|
|
|
|
|
|
|
3 => [], |
31
|
|
|
|
|
|
|
); |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
while (my ($number, $power) = each %numbers) { |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
# this will be a superposition of all valid powers |
36
|
|
|
|
|
|
|
my $power_superposition = power_sources $number; |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
# there should be 1 or 0 resulting states |
39
|
|
|
|
|
|
|
my $state = $power_superposition->states->[0]; |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
if (!defined $state) { |
42
|
|
|
|
|
|
|
is scalar $power->@*, 0; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
else { |
45
|
|
|
|
|
|
|
my @sources = $state->source->@*; |
46
|
|
|
|
|
|
|
is scalar @sources, scalar $power->@*; |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
# did we succeed? |
49
|
|
|
|
|
|
|
FACTOR: |
50
|
|
|
|
|
|
|
foreach my $factor ($power->@*) { |
51
|
|
|
|
|
|
|
my ($base, $exponent) = $factor->@*; |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
foreach my $source (@sources) { |
54
|
|
|
|
|
|
|
next FACTOR |
55
|
|
|
|
|
|
|
if $source->[0] eq $base && $source->[1] eq $exponent; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
fail; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
done_testing; |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
__END__ |