mirror of
https://github.com/Justuser3310/ss14_chemistry_site.git
synced 2025-01-18 16:58:48 +00:00
51 lines
1.2 KiB
Python
51 lines
1.2 KiB
Python
global expanded
|
|
def expand_recipe(recipe, recipes, main = False):
|
|
global expanded
|
|
if main:
|
|
expanded = {}
|
|
|
|
ok = False
|
|
part = 1 # Одна часть
|
|
while not ok:
|
|
ok = True
|
|
vol_in = 0 # Объём мин. рецепта (вход)
|
|
# Перебираем элементы
|
|
for el in recipe:
|
|
# Если составное
|
|
if el in recipes:
|
|
# Одна часть должна делиться без остатка!
|
|
if part % recipes[el].out != 0:
|
|
ok = False
|
|
part += 1
|
|
expanded = {}
|
|
break
|
|
else:
|
|
vol_in += expand_recipe(recipes[el].comps, recipes)
|
|
else:
|
|
if el in expanded:
|
|
expanded[el] += recipe[el]*part
|
|
else:
|
|
expanded[el] = recipe[el]*part
|
|
|
|
vol_in += recipe[el]*part
|
|
|
|
if main:
|
|
return expanded, vol_in, part
|
|
else:
|
|
return vol_in
|
|
|
|
def calc(element, amount, recipes):
|
|
# Получаем характеристику элемента
|
|
recipe, vol_out = recipes[element].comps, recipes[element].out
|
|
# Расчитываем минимальный рецепт
|
|
expanded, vol_in, part = expand_recipe(recipe, recipes, True)
|
|
|
|
need = amount//vol_in
|
|
for i in expanded:
|
|
expanded[i] = expanded[i]*need
|
|
vol_in *= need
|
|
vol_out *= part*need
|
|
|
|
return expanded, vol_in, vol_out
|
|
|