Compare commits

..

3 Commits

Author SHA1 Message Date
justuser31
22b2a0ec27 Мелкие поправки, комментарии. 2024-05-01 15:14:33 +03:00
justuser31
eb13e945b9 Merge branch 'main' of github.com:Justuser3310/ss14_chemistry_site 2024-05-01 15:11:19 +03:00
justuser31
0d3bd86b2c Новый алгоритм, ура. 2024-05-01 15:07:43 +03:00

39
reworked/calc.py Normal file
View File

@ -0,0 +1,39 @@
def expand_recipe(recipe, recipes):
global expanded
ok = False
part = 1 # Одна часть
while not ok:
ok = True
# Перебираем элементы
for el in recipe:
# Если составное
if el in recipes:
# Одна часть должна делиться без остатка!
if part % recipes[el].out != 0:
ok = False
part += 1
expanded = {}
break
else:
expand_recipe(recipes[el].comps, recipes)
else:
if el in expanded:
expanded[el] += recipe[el]*part
else:
expanded[el] = recipe[el]*part
def calc(element, amount, recipes):
# TODO: Пока только выводит расширенную версию рецепта
recipe, out = recipes[element].comps, recipes[element].out
global expanded
expanded = {}
expand_recipe(recipe, recipes)
return expanded
from parse import *
#print( load_recipes() )
print( calc('Dylovene', 100, load_recipes()) )