« blib/lib/Quantum/Superpositions/Lazy/Role/Collapsible.pm
↑ Summary
blib/lib/Quantum/Superpositions/Lazy/Operation/Computational.pm »
| 1 | 1 | ▶ | use v5.24; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 2 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use Test::More; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use Q::S::L qw(superpos fetch_matches with_sources); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | sub power_sources | ||||||||||||||||||||||||||||
| 7 | 4 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
power_sources: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 4 | my ($number) = @_; | |||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | # produce all the possible bases end exponents | ||||||||||||||||||||||||||||
| 11 | 4 | my $possible_bases = superpos(2 .. sqrt $number); | |||||||||||||||||||||||||||
| 12 | 4 | my $possible_exponents = superpos(2 .. sqrt $number); | |||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | # produce all possible powers | ||||||||||||||||||||||||||||
| 15 | 4 | 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 | 4 | ▶ | return fetch_matches { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 20 | 4 | ▶ | with_sources { $possible_powers == $number } | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 21 | 4 | }; | |||||||||||||||||||||||||||
| 22 | } | ||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 1 | 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 | 1 | ▶ | while (my ($number, $power) = each %numbers) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | # this will be a superposition of all valid powers | ||||||||||||||||||||||||||||
| 36 | 4 | my $power_superposition = power_sources $number; | |||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | # there should be 1 or 0 resulting states | ||||||||||||||||||||||||||||
| 39 | 4 | my $state = $power_superposition->states->[0]; | |||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 4 | ▶ | if (!defined $state) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 42 | 1 | is scalar $power->@*, 0; | |||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||
| 44 | else { | ||||||||||||||||||||||||||||
| 45 | 3 | my @sources = $state->source->@*; | |||||||||||||||||||||||||||
| 46 | 3 | is scalar @sources, scalar $power->@*; | |||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | # did we succeed? | ||||||||||||||||||||||||||||
| 49 | FACTOR: | ||||||||||||||||||||||||||||
| 50 | 3 | foreach my $factor ($power->@*) { | |||||||||||||||||||||||||||
| 51 | 7 | my ($base, $exponent) = $factor->@*; | |||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | 7 | foreach my $source (@sources) { | |||||||||||||||||||||||||||
| 54 | next FACTOR | ||||||||||||||||||||||||||||
| 55 | 14 | ▶ | if $source->[0] eq $base && $source->[1] eq $exponent; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$source->[0] eq $base and $source->[1] eq $exponent
MC/DC50%1/2
$source->[0] eq $base and $source->[1] eq $exponent
$source->[0] eq $base
$source->[1] eq $exponent
Truth table66%2/3
A and B
A= $source->[0] eq $baseB= $source->[1] eq $exponent
| |||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||
| 57 | 0 | fail; | |||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 1 | done_testing; | |||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | __END__ | ||||||||||||||||||||||||||||