From 9004ded826953717e7a5fc745402ca51681e70b0 Mon Sep 17 00:00:00 2001 From: Michael Peters Date: Thu, 15 Feb 2024 20:13:33 -0800 Subject: [PATCH] add output for intermediate products --- calc2.py | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/calc2.py b/calc2.py index c6bf5b2..6cd7526 100644 --- a/calc2.py +++ b/calc2.py @@ -159,8 +159,11 @@ def add_recipe(targets: dict[str, float], recipe: dict[str, float], multiplier: } -def compute_base_resource_flow(targets: dict[str, float], base_resources: set[str]) -> dict[str, float]: +def compute_base_resource_flow( + targets: dict[str, float], base_resources: set[str] +) -> tuple[dict[str, float], dict[str, float]]: results = {} + intermediates = {} while len(targets) > 0: resource, count = next(iter(targets.items())) @@ -171,19 +174,20 @@ def compute_base_resource_flow(targets: dict[str, float], base_resources: set[st del targets[resource] continue + intermediates = add_recipe(intermediates, {resource: count}, -1) recipe = recipies[resource] multiplier = count / recipe[resource] targets = add_recipe(targets, recipe, multiplier) - return results + return results, intermediates SPM = 1 targets_groups: list[dict[str, float]] = [ - {'science-red': SPM}, - {'science-green': SPM}, - {'science-gray': SPM}, - {'science-blue': SPM}, + {'science-red': 1}, + {'science-green': 1}, + {'science-gray': 2}, + {'science-blue': 2}, ] base_resources = { 'iron-plate', @@ -201,8 +205,12 @@ base_resources = { print(f'{SPM=}') print(f'{base_resources=}') for targets in targets_groups: + results, intermediates = compute_base_resource_flow(targets, base_resources) print() print(f'{targets=}') - results = compute_base_resource_flow(targets, base_resources) + print('intermediates') + for resource, count in sorted(intermediates.items()): + print(f' {resource:25}: {count:.3g}') + print('results') for resource, count in sorted(results.items()): - print(f'{resource:30}: {count:.3g}') + print(f' {resource:25}: {count:.3g}')