From 32527fe39e927c178873164c8657b2514b086bc5 Mon Sep 17 00:00:00 2001 From: justuser31 Date: Thu, 2 May 2024 17:46:32 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=BC=D0=BD=D0=BE=D0=B6=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D1=80=D0=B5=D1=86=D0=B5=D0=BF=D1=82=D0=B0?= =?UTF-8?q?=20=D0=B8=20=D0=BC=D0=B5=D0=BB=D0=BA=D0=B8=D0=B5=20=D0=B4=D0=BE?= =?UTF-8?q?=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=BA=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- reworked/calc.py | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/reworked/calc.py b/reworked/calc.py index c26ac20..8d47e93 100644 --- a/reworked/calc.py +++ b/reworked/calc.py @@ -1,10 +1,12 @@ -def expand_recipe(recipe, recipes): +global expanded ; expanded = {} +def expand_recipe(recipe, recipes, main = False): global expanded ok = False part = 1 # Одна часть while not ok: ok = True + min_vol = 0 # Объём мин. рецепта (вход) # Перебираем элементы for el in recipe: # Если составное @@ -16,24 +18,35 @@ def expand_recipe(recipe, recipes): expanded = {} break else: - expand_recipe(recipes[el].comps, recipes) + min_vol += expand_recipe(recipes[el].comps, recipes) else: if el in expanded: expanded[el] += recipe[el]*part else: expanded[el] = recipe[el]*part + min_vol += recipe[el]*part + + if main: + return expanded, min_vol, part + else: + return min_vol + def calc(element, amount, recipes): - # TODO: Пока только выводит расширенную версию рецепта + # Получаем характеристику элемента recipe, out = recipes[element].comps, recipes[element].out + # Расчитываем минимальный рецепт + expanded, vol, part = expand_recipe(recipe, recipes, True) - global expanded - expanded = {} - expand_recipe(recipe, recipes) + # Домнажаем на сколько нужно + need = amount//vol + for i in expanded: + expanded[i] = expanded[i]*need + out = part*out*need - return expanded + return expanded, out from parse import * #print( load_recipes() ) -print( calc('Dylovene', 100, load_recipes()) ) +print( calc('Leporazine', 100, load_recipes()) )