add output for intermediate products

This commit is contained in:
Michael Peters 2024-02-15 20:13:33 -08:00
parent 83e4ffbdf1
commit 9004ded826

View File

@ -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}')