First version with all variables calculated in a token list. 'Factor Engine' starts here.

This commit is contained in:
2020-04-20 00:19:49 -05:00
parent 0d7fe94942
commit 08bb51d68e
2 changed files with 16 additions and 6 deletions
+11 -6
View File
@@ -17,6 +17,7 @@ base_list = [2, 4, 6, 12]
with open("expression.json", "r") as f:
#j = json.load(f)
exp = jsonpickle.decode(f.read())
exp.variables
#results = calc_engine.calculate_results(tokens.copy())
#print(results)
@@ -25,6 +26,9 @@ with open("expression.json", "r") as f:
#print()
tokens = tokenizer.get_tokens_from_expression_string(exp.expression)
tokenizer.print_token_list(tokens)
factors_list = []
ls = []
for v in exp.variables:
factor = factors.Factor(v, base_list)
@@ -34,10 +38,11 @@ for v in exp.variables:
else:
factor.calculate_factors(exp.variables[v].starting_point)
#for result in calc_answers(f, m):
calc_answers(factor, exp.variables[v].starting_point, exp.variables[v].type, exp.wrong_response)
def calc_answers(factor_object, starting_point, variable_type, wrong_response):
pass
factors_list.append(factor)
ls.append(factor.get_flat_factors_list())
res = list(itertools.product(*ls))
for r in res:
t = tokenizer.replace_variables(tokens, list(r))
#tokenizer.print_token_list(t)
print("Results %f" %(calc_engine.calculate_results(t)))
+5
View File
@@ -82,3 +82,8 @@ def replace_variables(tokens, new_constants):
newTokenList.append(token.Token(t.value, t.type))
return newTokenList
def print_token_list(tokens):
for tk in tokens:
print(tk.value, end = "")
print()