From bde768251886a3aee04b322c22cff451fc24cddc Mon Sep 17 00:00:00 2001 From: Michael Peters Date: Thu, 15 Feb 2024 21:05:12 -0800 Subject: [PATCH] compute final bus compontents --- calc2.py | 43 ++++++++++++++++++++++++++++++++++++------- 1 file changed, 36 insertions(+), 7 deletions(-) diff --git a/calc2.py b/calc2.py index 6cd7526..1912b5a 100644 --- a/calc2.py +++ b/calc2.py @@ -1,4 +1,19 @@ -from pprint import pformat, pprint +from functools import lru_cache, partial + + +@lru_cache +def _dot_align(seq: tuple[float, ...]) -> dict[float, str]: + strs = [(f'{n:.9g}', n) for n in seq] + dots = [(s.find('.') if '.' in s else len(s), s, n) for s, n in strs] + md, _, _ = max(dots) + rv = {n: (' ' * (md - d) + s)[: md + 4] for d, s, n in dots} + assert not all(s.startswith(' ') for s in rv.values()) + return rv + + +def dot_align(seq: tuple[float, ...], n) -> str: + return _dot_align(seq)[n] + recipies: dict[str, dict[str, float]] = { # mining @@ -184,10 +199,12 @@ def compute_base_resource_flow( SPM = 1 targets_groups: list[dict[str, float]] = [ - {'science-red': 1}, - {'science-green': 1}, - {'science-gray': 2}, - {'science-blue': 2}, + {'science-red': SPM}, + {'science-green': SPM}, + {'science-gray': SPM}, + {'science-blue': SPM}, + {'science-purple': SPM}, + {'science-yellow': SPM}, ] base_resources = { 'iron-plate', @@ -198,19 +215,31 @@ base_resources = { 'steel', 'sulfur', 'plastic', + 'sulfuric-acid', + 'lubricant', } # TODO: science-blue is wrong print(f'{SPM=}') print(f'{base_resources=}') +bus_inputs = {} for targets in targets_groups: results, intermediates = compute_base_resource_flow(targets, base_resources) print() print(f'{targets=}') print('intermediates') for resource, count in sorted(intermediates.items()): - print(f' {resource:25}: {count:.3g}') + print(f' {resource:35}: {dot_align(tuple(intermediates.values()), count)}') print('results') for resource, count in sorted(results.items()): - print(f' {resource:25}: {count:.3g}') + print(f' {resource:35}: {dot_align(tuple(results.values()), count)}') + + bus_inputs = add_recipe(bus_inputs, results, -1) + +print() +print('final bus inputs') +for resource, count in sorted(bus_inputs.items()): + if resource.startswith(('assembler', 'chemical-plant', 'oil-refinery')): + continue + print(f' {resource:35}: {dot_align(tuple(bus_inputs.values()), count)}')