Greedy algorithm for Egyptian fractions: Difference between revisions
Greedy algorithm for Egyptian fractions (view source)
Revision as of 17:29, 3 August 2019
, 4 years ago→{{header|Phix}}: bugfix
m (→{{header|Phix}}: bigatom -> mpfr) |
m (→{{header|Phix}}: bugfix) |
||
Line 1,693:
procedure efrac(integer num, denom)
string
prefix = ""
if num>=denom then
integer whole = floor(num/denom)
Line 1,700 ⟶ 1,701:
end if
string e = join(egyptian(num, denom)," + ")
printf(1,"%
end procedure
Line 1,754 ⟶ 1,755:
43/48 -> 1/2 + 1/3 + 1/16
5/121 -> 1/25 + 1/757 + 1/763309 + 1/873960180913 + 1/1527612795642093418846225
for proper fractions with 1 to 2 digits
|