From 0d3bd86b2c4c844006534293df8addeef79d5e4c Mon Sep 17 00:00:00 2001 From: justuser31 Date: Wed, 1 May 2024 15:07:43 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9D=D0=BE=D0=B2=D1=8B=D0=B9=20=D0=B0=D0=BB?= =?UTF-8?q?=D0=B3=D0=BE=D1=80=D0=B8=D1=82=D0=BC,=20=D1=83=D1=80=D0=B0.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- reworked/calc.py | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 reworked/calc.py diff --git a/reworked/calc.py b/reworked/calc.py new file mode 100644 index 0000000..1d5cfb9 --- /dev/null +++ b/reworked/calc.py @@ -0,0 +1,36 @@ +def expand_recipe(recipe, recipes, main = False): + 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, True) + + return expanded + + +from parse import * +#print( load_recipes() ) +print( calc('Dylovene', 100, load_recipes()) )