Skip to content

Commit ea97438

Browse files
committed
Added Egyptian Fraction
1 parent cc2b538 commit ea97438

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
"""
2+
Author : Robin Singh
3+
Implementation of Eqyption Fraction
4+
Every positive fraction can be represented as sum of unique unit fractions
5+
A fraction is unit fraction if numerator is 1 and denominator is a positive integer, for example 1/3 is a unit fraction
6+
Such a representation is called Egyptian Fraction as it was used by ancient Egyptians
7+
"""
8+
9+
import math
10+
def egyptianFraction(numerator, denominator):
11+
ef = []
12+
while numerator != 0:
13+
14+
x = math.ceil(denominator / numerator) #Main
15+
ef.append(x)
16+
numerator = x * numerator - denominator
17+
denominator = denominator * x
18+
for i in range(len(ef)):
19+
if i != len(ef) - 1:
20+
print(f" 1/{ef[i]} +",end=" ")
21+
22+
else:
23+
print(f"1/{ef[i]}",end=" ")
24+
25+
if __name__ == '__main__':
26+
nr = int(input("Enter numerator"))
27+
dr = int(input("Enter denominator"))
28+
print(f"Egyptian Fraction of {nr}/{dr} : ")
29+
egyptianFraction(nr,dr)

0 commit comments

Comments
 (0)