From 644ba22d1b7f82d841dd662cb1e027431048f971 Mon Sep 17 00:00:00 2001 From: = <=> Date: Tue, 6 Feb 2024 17:02:16 +0100 Subject: [PATCH] fixed import and infinite growth --- python/main.py | 19 ++++++++++++++++--- python/polycube.py | 5 +++-- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/python/main.py b/python/main.py index 82c541f..d91ef30 100644 --- a/python/main.py +++ b/python/main.py @@ -1,6 +1,19 @@ +from polycube import PolyCube +import json -def main(): - pass +def main(maxlength:int): + polycubes = {} + todo = [PolyCube([(0, 0, 0)], [(0, 0, 0)])] + while len(todo) != 0: + polycube = todo.pop() + children = polycube.generate_children(maxlength) + for child in children: + if child in polycubes: + continue + todo.append(child) + polycubes[child] = 0 + with open("out.json", "w") as f: + f.write(json.dumps(polycubes)) if __name__ == "__main__": - main() + main(4) diff --git a/python/polycube.py b/python/polycube.py index 89a9dc7..7b3109b 100644 --- a/python/polycube.py +++ b/python/polycube.py @@ -1,4 +1,4 @@ -from python.tuple_tools import reorient_tuple, generate_neighbors +from tuple_tools import reorient_tuple, generate_neighbors from itertools import combinations, chain class PolyCube: @@ -22,11 +22,12 @@ class PolyCube: self.orientations = orientations def generate_children(self, max_length:int): + max_growth = max_length - len(self.cubes) growth_candidates = set([]) for last_addition in self.last_additions: growth_candidates = growth_candidates.union(generate_neighbors(*last_addition)) growth_candidates = growth_candidates.difference(self.cubes) - realizable_growth = chain(combinations(growth_candidates, i) for i in range(1, max_length+1)) + realizable_growth = chain(combinations(growth_candidates, i) for i in range(1, max_growth+1)) for addition in realizable_growth: yield PolyCube(self.cubes.union(addition), addition)