Solve the issue with self missplacement

This commit is contained in:
Lafrite 2013-10-30 19:34:39 +01:00
parent f4ea0dcc42
commit decffa6d75
2 changed files with 7 additions and 10 deletions

View File

@ -346,7 +346,6 @@ def test(exp):
#print("Bis") #print("Bis")
steps = [postfix] steps = [postfix]
steps += computePostfixBis(postfix) steps += computePostfixBis(postfix)
print(steps)
print_steps(steps) print_steps(steps)
#print(postfixToInfix(postfix)) #print(postfixToInfix(postfix))
#print(get_main_op(exp)) #print(get_main_op(exp))

View File

@ -24,22 +24,20 @@ class Fraction(object):
steps = [] steps = []
if self._denom < 0: if self._denom < 0:
self._num = - self._num n_frac = Fraction(-self._num, -self._denom)
self._denom = - self._denom steps.append(n_frac)
steps.append(self)
gcd_ = gcd(abs(self._num), abs(self._denom)) gcd_ = gcd(abs(self._num), abs(self._denom))
if self._num == self._denom: if self._num == self._denom:
self._num = 1 n_frac = Fraction(1,1)
self._denom = 1 steps.append(n_frac)
steps.append(self)
elif gcd_ != 1: elif gcd_ != 1:
self._num, self._denom = self._num // gcd_ , self._denom // gcd_ n_frac = Fraction(self._num // gcd_ , self._denom // gcd_)
steps.append("( {reste1} * {gcd} ) / ( {reste2} * {gcd} )".format(reste1 = self._num, reste2 = self._denom, gcd = gcd_)) steps.append("( {reste1} * {gcd} ) / ( {reste2} * {gcd} )".format(reste1 = n_frac._num, reste2 = n_frac._denom, gcd = gcd_))
# Certainement le truc le plus moche que j'ai jamais fait... On ne met que des strings dans steps puis au dernier moment on met une fraction. C'est moche de ma part # Certainement le truc le plus moche que j'ai jamais fait... On ne met que des strings dans steps puis au dernier moment on met une fraction. C'est moche de ma part
steps.append(self) steps.append(n_frac)
return steps return steps