Skip to content

Instantly share code, notes, and snippets.

@showyou
Created March 6, 2010 11:14
Show Gist options
  • Select an option

  • Save showyou/323634 to your computer and use it in GitHub Desktop.

Select an option

Save showyou/323634 to your computer and use it in GitHub Desktop.
# usage: egipt.py child mother
# egipt.py 1 2
# = 1/2
class Fraction:
def __init__(self, child, mother):
self.child = child
self.mother = mother
def __str__(self):
return str(self.child)+"/"+str(self.mother)
def __sub__(self, other):
newMother = self.mother * other.mother
newChild = self.child * other.mother - self.mother
return Fraction( newChild, newMother )
def __cmp__(self, other):
return self.child * other.mother - other.child * self.mother
def egipt(a, b):
input = Fraction( int(a),int(b) )
list = []
n = 2
while n < 10000000:
print "now", input
value = Fraction( 1, n )
print value
if value == input:
list.append(value)
break
elif value < input:
input -= value
print "minus", value
list.append(value)
n+= 1
print "answer:"
for l in list:
print l
if __name__ == '__main__':
import sys
egipt(sys.argv[1], sys.argv[2])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment