add output for intermediate products
This commit is contained in:
parent
83e4ffbdf1
commit
9004ded826
24
calc2.py
24
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 = {}
|
results = {}
|
||||||
|
intermediates = {}
|
||||||
|
|
||||||
while len(targets) > 0:
|
while len(targets) > 0:
|
||||||
resource, count = next(iter(targets.items()))
|
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]
|
del targets[resource]
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
intermediates = add_recipe(intermediates, {resource: count}, -1)
|
||||||
recipe = recipies[resource]
|
recipe = recipies[resource]
|
||||||
multiplier = count / recipe[resource]
|
multiplier = count / recipe[resource]
|
||||||
targets = add_recipe(targets, recipe, multiplier)
|
targets = add_recipe(targets, recipe, multiplier)
|
||||||
|
|
||||||
return results
|
return results, intermediates
|
||||||
|
|
||||||
|
|
||||||
SPM = 1
|
SPM = 1
|
||||||
targets_groups: list[dict[str, float]] = [
|
targets_groups: list[dict[str, float]] = [
|
||||||
{'science-red': SPM},
|
{'science-red': 1},
|
||||||
{'science-green': SPM},
|
{'science-green': 1},
|
||||||
{'science-gray': SPM},
|
{'science-gray': 2},
|
||||||
{'science-blue': SPM},
|
{'science-blue': 2},
|
||||||
]
|
]
|
||||||
base_resources = {
|
base_resources = {
|
||||||
'iron-plate',
|
'iron-plate',
|
||||||
@ -201,8 +205,12 @@ base_resources = {
|
|||||||
print(f'{SPM=}')
|
print(f'{SPM=}')
|
||||||
print(f'{base_resources=}')
|
print(f'{base_resources=}')
|
||||||
for targets in targets_groups:
|
for targets in targets_groups:
|
||||||
|
results, intermediates = compute_base_resource_flow(targets, base_resources)
|
||||||
print()
|
print()
|
||||||
print(f'{targets=}')
|
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()):
|
for resource, count in sorted(results.items()):
|
||||||
print(f'{resource:30}: {count:.3g}')
|
print(f' {resource:25}: {count:.3g}')
|
||||||
|
Loading…
Reference in New Issue
Block a user