Skip to content

Commit

Permalink
Working on the calculator
Browse files Browse the repository at this point in the history
  • Loading branch information
jonahmakowski committed Nov 21, 2023
1 parent 79abac9 commit b2b80e4
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions src/calculator_with_parser/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,20 +212,20 @@ def __init__(self, expression):
def solve(self):
while len(self.expression.expression) > 1:
indexes = []
versions = [self.expression.expression]
versions = [self.expression]
cur_expression = self.expression
index = 0
expression_found = True
while expression_found:
expression_found = False
index = 0
for item in cur_expression.expression:
if item.tt == TT_EXPRESSION:
expression_found = True
cur_expression = item
indexes.append(index)
versions.append(cur_expression.expression)
versions.append(cur_expression.copy())
break
index += 1
index += 1
if not expression_found:
break

Expand All @@ -251,14 +251,18 @@ def solve(self):
self.expression = final_solve

def replace_old(self, new_num, indexes, versions):
versions_new = versions.copy()
versions_new[-1] = new_num

for i in range(len(versions)-2, 0, -1):
versions_new[i] = versions_new[i+1]

self.expression.expressions = versions_new[0]

cur = versions[-2].expression.copy()
cur1 = []
cur[indexes[-1]] = new_num
del indexes[-1]
del versions[-2]
for item in versions:
cur1 = cur
cur = item
cur[indexes[-1]] = cur1
del indexes[-1]
self.expression = Expression(cur)

@staticmethod
def simple_solve_mul_div(expression):
found = False
Expand Down

0 comments on commit b2b80e4

Please sign in to comment.