| 1 | package Math::Fraction::Egyptian; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 14 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 14 | ▶ | use warnings FATAL => 'all'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 14 | ▶ | use base 'Exporter'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 14 | ▶ | use List::Util qw(first reduce max); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 14 | our @EXPORT_OK = qw( to_egyptian to_common ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 14 | our %EXPORT_TAGS = (all => \@EXPORT_OK); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 14 | our $VERSION = '0.01'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 14 | my %PRIMES = map { $_ => 1 } primes(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | Math::Fraction::Egyptian - construct Egyptian representations of fractions | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | use Math::Fraction::Egyptian ':all'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | my @e = to_egyptian(43, 48); # returns 43/48 in Egyptian format | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | my @v = to_common(2, 3, 16); # returns 1/2 + 1/3 + 1/16 in common format | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | From L<Wikipedia|http://en.wikipedia.org/wiki/Egyptian_fractions>: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | An Egyptian fraction is the sum of distinct unit fractions, such as | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 1/2 + 1/3 + 1/16 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | That is, each fraction in the expression has a numerator equal to 1 and a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | denominator that is a positive integer, and all the denominators differ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | from each other. The sum of an expression of this type is a positive | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | rational number C<a/b>; for instance the Egyptian fraction above sums to | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | C<43/48>. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | Every positive rational number can be represented by an Egyptian fraction. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | Sums of this type, and similar sums also including C<2/3> and C<3/4> as | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | summands, were used as a serious notation for rational numbers by the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | ancient Egyptians, and continued to be used by other civilizations into | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | medieval times. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | In modern mathematical notation, Egyptian fractions have been superseded by | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | L<vulgar fractions|http://en.wikipedia.org/wiki/Vulgar_fraction> and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | decimal notation. However, Egyptian fractions continue to be an object of | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | study in modern number theory and recreational mathematics, as well as in | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | modern historical studies of ancient mathematics. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | =back | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | A common fraction has an infinite number of different Egyptian fraction | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | representations. This module only implements a handful of conversion | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | strategies for conversion of common fractions to Egyptian form; see section | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | L<STRATEGIES> below for details. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | =head1 FUNCTIONS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | =head2 to_egyptian($numer, $denom, %attr) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | Converts fraction C<$numer/$denom> to its Egyptian representation. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | Example: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | my @egypt = to_egyptian(5,9); # converts 5/9 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | print "@egypt"; # prints FIXME | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 60 | ▶ | sub to_egyptian { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
to_egyptian: called CC=6 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 60 | my ($n,$d,%attr) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 60 | ($n,$d) = (abs(int($n)), abs(int($d))); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 60 | ▶ | $attr{dispatch} ||= \&_dispatch; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$attr{"dispatch"} ||= \&Math::Fraction::Egyptian::_dispatch
MC/DC0%0/1
$attr{"dispatch"} ||= \&Math::Fraction::Egyptian::_dispatch
$attr{"dispatch"}
Truth table50%1/2
A
A= $attr{"dispatch"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | # oh come on | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 60 | ▶ | if ($d == 0) { die "can't convert $n/$d"; } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | # handle improper fractions | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 57 | ▶ | if ($n >= $d) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 2 | my $n2 = $n % $d; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 2 | warn "$n/$d is an improper fraction; expanding $n2/$d instead"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 2 | $n = $n2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 57 | my @egypt; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 57 | ▶ | while ($n && $n != 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$n and $n != 0
MC/DC50%1/2
$n and $n != 0
$n
$n != 0
Truth table66%2/3
A and B
A= $nB= $n != 0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 53 | ($n, $d, my @e) = $attr{dispatch}->($n,$d); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 53 | push @egypt, @e; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 57 | return @egypt; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | # default strategy dispatcher | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 53 | ▶ | sub _dispatch { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_dispatch: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 53 | my ($n, $d) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 53 | my @egypt; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 53 | my @strategies = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | [ trivial => \&s_trivial, ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | [ small_prime => \&s_small_prime, ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | [ practical_strict => \&s_practical_strict, ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | [ practical => \&s_practical, ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | [ greedy => \&s_greedy, ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | STRATEGY: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 53 | for my $s (@strategies) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 187 | my ($name,$coderef) = @$s; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 187 | my @result = eval { $coderef->($n,$d); }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 187 | ▶ | next STRATEGY if $@; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 53 | my ($n2, $d2, @e2) = @result; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 53 | ($n,$d) = ($n2,$d2); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 53 | push @egypt, @e2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 53 | last STRATEGY; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 53 | return $n, $d, @egypt; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | =head2 to_common(@denominators) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | Converts an Egyptian fraction into a common fraction. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | Example: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | my ($num,$den) = to_common(2,5,11); # 1/2 + 1/5 + 1/11 = ? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | print "$num/$den"; # prints "87/110" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 8 | ▶ | sub to_common { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
to_common: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 8 | my ($n,$d) = (0,1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 8 | for my $a (@_) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 18 | ($n, $d) = simplify($a * $n + $d, $a * $d); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 8 | return ($n,$d); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | =head2 GCD($x,$y) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | Uses Euclid's algorithm to determine the greatest common denominator | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | ("GCD") of C<$x> and C<$y>. Returns the GCD. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 115 | ▶ | sub GCD { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
GCD: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 115 | my ($x, $y) = (int($_[0]), int($_[1])); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 115 | ▶ | return ($y) ? GCD($y, $x % $y) : $x; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | =head2 simplify($n,$d) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | Reduces fraction C<$n/$d> to simplest terms. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | Example: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | my @x = simplify(25,100); # @x is (1,4) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 25 | ▶ | sub simplify { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
simplify: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 25 | my ($n, $d) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 25 | my $gcd = GCD($n,$d); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 25 | return ($n / $gcd, $d / $gcd); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | =head2 primes() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | Returns a list of all prime numbers below 1000. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 1162 | ▶ | sub primes { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
primes: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 1162 | return qw( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | 97 101 103 107 109 113 127 131 137 139 149 151 157 163 167 173 179 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 181 191 193 197 199 211 223 227 229 233 239 241 251 257 263 269 271 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 277 281 283 293 307 311 313 317 331 337 347 349 353 359 367 373 379 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 383 389 397 401 409 419 421 431 433 439 443 449 457 461 463 467 479 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 487 491 499 503 509 521 523 541 547 557 563 569 571 577 587 593 599 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | 601 607 613 617 619 631 641 643 647 653 659 661 673 677 683 691 701 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | 709 719 727 733 739 743 751 757 761 769 773 787 797 809 811 821 823 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 827 829 839 853 857 859 863 877 881 883 887 907 911 919 929 937 941 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | 947 953 967 971 977 983 991 997 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | =head2 prime_factors($n) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | Returns the prime factors of C<$n> as a list of (prime,multiplicity) pairs. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | The list is sorted by increasing prime number. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | Example: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | my @pf = prime_factors(120); # 120 = 2 * 2 * 2 * 3 * 5 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | # @pf = ([2,3],[3,1],[5,1]) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | 1148 | ▶ | sub prime_factors { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
prime_factors: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | 1148 | my $n = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | 1148 | my @primes = primes(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 1148 | my %pf; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 1148 | for my $i (0 .. $#primes) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | 14483 | my $p = $primes[$i]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | 14483 | ▶ | while ($n % $p == 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | 5493 | $pf{$p}++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | 5493 | $n /= $p; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 14483 | ▶ | last if $n == 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 1148 | ▶ | return unless $n == 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | 1148 | return map { [ $_, $pf{$_} ] } sort { $a <=> $b } keys %pf; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | =head2 decompose($n) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | If C<$n> is a composite number, returns ($p,$q) such that: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | * $p != 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | * $q != 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | * $p x $q == $n | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | 5 | ▶ | sub decompose { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
decompose: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | 5 | my @pf = reverse map { ($_->[0]) x $_->[1] } prime_factors($_[0]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 5 | my ($p, $q) = (1, 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | 5 | for my $f (@pf) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | 11 | ▶ | if ($p < $q) { $p *= $f } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | 5 | else { $q *= $f } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | 5 | return sort { $a <=> $b } $p, $q; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | =head2 sigma(@pairs) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | Helper function for determining whether a number is "practical" or not. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | 2156 | ▶ | sub sigma { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
sigma: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | # see http://en.wikipedia.org/wiki/Divisor_function | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | 2156 | my @pairs = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | 3464 | ▶ | my $term = sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | 3464 | my ($p,$a) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | 3464 | return (($p ** ($a + 1)) - 1) / ($p - 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | 2156 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | 2156 | ▶ | return reduce { $a * $b } map { $term->(@$_) } @pairs; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | =head1 STRATEGIES | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | Fibonacci, in his Liber Abaci, identifies seven different methods for | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | converting common to Egyptian fractions: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | =item 1. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | =item 2. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | =item 3. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | =item 4. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | =item 5. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | =item 6. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | =item 7. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | =back | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | The strategies as implemented below have the following features in common: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | =item * | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | Each function call has a signature of the form C<I<strategy>($numerator, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | $denominator)>. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | =item * | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | The return value from a successful strategy call is the list C<($numerator, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | $denominator, @egyptian)>: the new numerator, the new denominator, and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | zero or more new Egyptian factors extracted from the input fraction. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | =item * | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | Some strategies are not applicable to all inputs. If the strategy | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | determines that it cannot determine the next number in the expansion, it | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | throws an exception (via C<die()>) to indicate the strategy is unsuitable. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | =back | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | =head2 s_trivial($n,$d) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | Strategy for dealing with "trivial" expansions--if C<$n> is C<1>, then this | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | fraction is already in Egyptian form. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | Example: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | my @x = s_trivial(1,5); # @x = (0,1,5) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | 55 | ▶ | sub s_trivial { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
s_trivial: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | 55 | my ($n,$d) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | 55 | ▶ | if (defined($n) && $n == 1) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $n and $n == 1
MC/DC50%1/2
defined $n and $n == 1
defined $n
$n == 1
Truth table66%2/3
A and B
A= defined $nB= $n == 1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | 4 | return (0,1,$d); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | 51 | die "unsuitable strategy"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | =head2 s_small_prime($n,$d) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | For a numerator of 2 with odd prime denominator d, one can use this | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | expansion: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | 2/d = 2/(d + 1) + 2/d(d + 1) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | 52 | ▶ | sub s_small_prime { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
s_small_prime: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | 52 | my ($n,$d) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | 52 | ▶ | if ($n == 2 && $d > 2 && $d < 30 && $PRIMES{$d}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition88%8/9
$n == 2 and $d > 2 and $d < 30 and $PRIMES{$d}
$n == 2 and $d > 2 and $d < 30
$n == 2 and $d > 2
MC/DC75%3/4
$n == 2 and $d > 2 and $d < 30 and $PRIMES{$d}
$n == 2
$d > 2
$d < 30
$PRIMES{$d}
Truth table80%4/5
A and B and C and D
A= $n == 2B= $d > 2C= $d < 30D= $PRIMES{$d}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | 9 | my $x = ($d + 1) / 2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | 9 | return (0, 1, $x, $d * $x); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | 43 | die "unsuitable strategy"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | =head2 s_practical($n,$d) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | Attempts to find a multiplier C<$M> such that the scaled denominator C<$M * | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | $d> is a practical number. This lets us break up the scaled numerator C<$M | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | * $numer> as in this example: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | examining 2/9: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | 9 * 2 is 18, and 18 is a practical number | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | choose $M = 2 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | scale 2/9 => 4/18 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | = 3/18 + 1/18 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | = 1/6 + 1/18 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | By definition, all numbers N < P, where P is practical, can be represented | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | as a sum of distinct divisors of P. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | 43 | ▶ | sub s_practical { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
s_practical: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | 43 | my ($n,$d) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | # look for a multiple of $d that is a practical number | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | 43 | ▶ | my $M = first { is_practical($_ * $d) } 1 .. $d; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | 43 | ▶ | die "unsuitable strategy" unless $M; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | 43 | $n *= $M; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | 43 | $d *= $M; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | 43 | my @divisors = grep { $d % $_ == 0 } 1 .. $d; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | 43 | my @N; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | my %seen; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | 43 | ▶ | while ($n) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | 122 | @divisors = grep { $_ <= $n } @divisors; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | 122 | my $x = max @divisors; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | 122 | push @N, $x; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | 122 | $n -= $x; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | 122 | @divisors = grep { $_ < $x } @divisors; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | 43 | my @e = map { $d / $_ } @N; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | 43 | return (0, 1, @e); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | =head2 s_practical_strict($n,$d) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | 42 | ▶ | sub s_practical_strict { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
s_practical_strict: called CC=7 SCAR=27.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | 42 | my ($N,$D) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | # find multiples of $d that are practical numbers | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | 42 | my @mult = grep { is_practical($_ * $D) } 1 .. $D; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | 42 | ▶ | die "unsuitable strategy" unless @mult; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | MULTIPLE: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | 42 | for my $M (@mult) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | 785 | my $n = $N * $M; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | 785 | my $d = $D * $M; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 406 | # find the divisors of $d | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | 785 | my @div = grep { $d % $_ == 0 } 1 .. $d; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 409 | # expand $n into a sum of divisors of $d | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | 785 | my @N; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | 785 | ▶ | while ($n) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 412 | 785 | ▶ | next MULTIPLE unless @N; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 413 | 0 | @div = grep { $_ <= $n } @div; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 414 | 0 | my $x = max @div; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 415 | 0 | push @N, $x; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 416 | 0 | $n -= $x; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 417 | 0 | @div = grep { $_ < $x } @div; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 418 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 419 | 0 | my @e = map { $d / $_ } @N; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 420 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 421 | 0 | ▶ | next MULTIPLE if $e[0] != $M; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 422 | 0 | ▶ | next MULTIPLE if grep { $d % $_ } @e[1 .. $#e]; # FIXME | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 423 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 424 | # o | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 425 | # 4. As an observation a1, ..., ai were always divisors of the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 426 | # denominator a of the first partition 1/a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 427 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 428 | 0 | return (0, 1, @e); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 429 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 430 | 42 | die "unsuitable strategy"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 431 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 432 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 433 | =head2 is_practical($n) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 434 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 435 | Returns a true value if C<$n> is a practical number. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 436 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 437 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 438 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 439 | 14 | my $_practical; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 440 | 3090 | ▶ | sub is_practical { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_practical: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 441 | 3090 | my $n = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 442 | 3090 | ▶ | unless (exists $_practical->{$n}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 443 | 2199 | $_practical->{$n} = _is_practical($n); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 444 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 445 | 3090 | return $_practical->{$n}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 446 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 447 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 448 | 2199 | ▶ | sub _is_practical { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_is_practical: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 449 | 2199 | my $n = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 450 | 2199 | ▶ | return 1 if $n == 1; # edge case | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 451 | 2198 | ▶ | return 0 if $n % 2 == 1; # no odd practicals except 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 452 | 1142 | my @pf = prime_factors($n); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 453 | 1142 | foreach my $i (1 .. $#pf) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 454 | 2136 | my $p = $pf[$i][0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 455 | 2136 | ▶ | return 0 if ($p > 1 + sigma( @pf[0 .. $i-1])); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 456 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 457 | 682 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 458 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 459 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 460 | =head2 s_composite($n,$d) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 461 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 462 | From L<Wikipedia|http://en.wikipedia.org/wiki/Egyptian_fraction>: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 463 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 464 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 465 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 466 | For composite denominators, factored as p×q, one can expand 2/pq using the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 467 | identity 2/pq = 1/aq + 1/apq, where a = (p+1)/2. Clearly p must be odd. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 468 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 469 | For instance, applying this method for d = pq = 21 gives p=3, q=7, and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 470 | a=(3+1)/2=2, producing the expansion 2/21 = 1/14 + 1/42. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 471 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 472 | =back | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 473 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 474 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 475 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 476 | 2 | ▶ | sub s_composite { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
s_composite: called CC=4 SCAR=16.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 477 | 2 | my ($n,$d) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 478 | 2 | ▶ | die "unsuitable strategy" if $PRIMES{$d}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 479 | 1 | my ($p,$q) = decompose($d); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 480 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 481 | # is $p odd | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 482 | 1 | ▶ | if ($p % 2 == 1) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 483 | 1 | my $a = ($p + 1) / 2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 484 | 1 | return (0, 1, $a * $q, $a * $p * $q); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 485 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 486 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 487 | # is $q odd | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 488 | 0 | ▶ | if ($q % 2 == 1) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 489 | 0 | my $a = ($q + 1) / 2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 490 | 0 | return (0, 1, $a * $p, $a * $p * $q); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 491 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 492 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 493 | 0 | die "unsuitable strategy"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 494 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 495 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 496 | =head2 s_greedy($n,$d) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 497 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 498 | Implements Fibonacci's greedy algorithm for computing Egyptian fractions: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 499 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 500 | n/d => 1/ceil(d/n) + ((-d)%n)/(d*ceil(d/n)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 501 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 502 | Example: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 503 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 504 | # performing the greedy expansion of 3/7: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 505 | # ceil(7/3) = 3 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 506 | # new numerator = (-7)%3 = 2 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 507 | # new denominator = 7 * 3 = 21 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 508 | # so 3/7 => 1/3 + 2/21 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 509 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 510 | my ($n,$d,$e) = greedy(2,7); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 511 | print "$n/$d ($e)"; # prints "2/21 (3)" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 512 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 513 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 514 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 515 | 5 | ▶ | sub s_greedy { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
s_greedy: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 516 | 14 | ▶ | use POSIX 'ceil'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 517 | 5 | my ($n,$d) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 518 | 5 | my $e = ceil( $d / $n ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 519 | 5 | ($n, $d) = simplify((-1 * $d) % $n, $d * $e); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 520 | 5 | return ($n, $d, $e); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 521 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 522 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 523 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 524 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 525 | John Trammell, C<< <johntrammell <at> gmail <dot> com> >> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 526 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 527 | =head1 BUGS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 528 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 529 | Please report any bugs or feature requests to C<bug-math-fraction-egyptian at | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 530 | rt.cpan.org>, or through | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 531 | the web interface at | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 532 | L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Math-Fraction-Egyptian>. I | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 533 | will be notified, and then you'll automatically be notified of progress on your | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 534 | bug as I make changes. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 535 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 536 | =head1 SUPPORT | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 537 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 538 | You can find documentation for this module with the perldoc command. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 539 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 540 | perldoc Math::Fraction::Egyptian | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 541 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 542 | You can also look for information at: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 543 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 544 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 545 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 546 | =item * GitHub | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 547 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 548 | L<http://github.com/jotr/math-fraction-egyptian> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 549 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 550 | =item * RT: CPAN's request tracker | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 551 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 552 | L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Math-Fraction-Egyptian> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 553 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 554 | =item * AnnoCPAN: Annotated CPAN documentation | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 555 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 556 | L<http://annocpan.org/dist/Math-Fraction-Egyptian> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 557 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 558 | =item * CPAN Ratings | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 559 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 560 | L<http://cpanratings.perl.org/d/Math-Fraction-Egyptian> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 561 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 562 | =item * Search CPAN | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 563 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 564 | L<http://search.cpan.org/dist/Math-Fraction-Egyptian/> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 565 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 566 | =back | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 567 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 568 | =head1 RESOURCES | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 569 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 570 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 571 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 572 | =item L<http://en.wikipedia.org/wiki/Category:Egyptian_fractions> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 573 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 574 | =item L<http://en.wikipedia.org/wiki/Common_fraction> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 575 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 576 | =item L<http://en.wikipedia.org/wiki/Rhind_Mathematical_Papyrus> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 577 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 578 | =item L<http://en.wikipedia.org/wiki/RMP_2/n_table> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 579 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 580 | =item L<http://en.wikipedia.org/wiki/Liber_Abaci> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 581 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 582 | =item L<http://en.wikipedia.org/wiki/Egyptian_fraction> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 583 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 584 | =item L<http://mathpages.com/home/kmath340/kmath340.htm> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 585 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 586 | =item L<http://mathworld.wolfram.com/RhindPapyrus.html> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 587 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 588 | =back | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 589 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 590 | =head1 ACKNOWLEDGEMENTS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 591 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 592 | Thanks to Project Euler, L<http://projecteuler.net/>, for stretching my mind | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 593 | into obscure areas of mathematics. C<< :-) >> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 594 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 595 | =head1 COPYRIGHT & LICENSE | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 596 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 597 | Copyright 2008 John Trammell, all rights reserved. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 598 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 599 | This program is free software; you can redistribute it and/or modify it | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 600 | under the same terms as Perl itself. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 601 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 602 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 603 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 604 | 14 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 605 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||