From 2ac37ad56734181c3f943032f140580e8b06fa6a Mon Sep 17 00:00:00 2001 From: Stefan Harmuth Date: Sun, 7 Aug 2022 18:45:33 +0200 Subject: [PATCH 1/4] pentagonal number sequence --- tools/int_seq.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tools/int_seq.py b/tools/int_seq.py index ee701a7..92b5250 100644 --- a/tools/int_seq.py +++ b/tools/int_seq.py @@ -28,3 +28,11 @@ def triangular(n: int) -> int: 0, 1, 3, 6, 10, 15, ... """ return n * (n + 1) // 2 + + +def pentagonal(n: int) -> int: + """ + A pentagonal number is a figurate number that extends the concept of triangular and square numbers to the pentagon + 0, 1, 5, 12, 22, 35, ... + """ + return ((3 * n * n) - n) / 2 From c752c286d20eac711eb4b21a3293a95fd0514c1d Mon Sep 17 00:00:00 2001 From: Stefan Harmuth Date: Sun, 7 Aug 2022 18:50:08 +0200 Subject: [PATCH 2/4] pentagonal number sequence (really int) --- tools/int_seq.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/int_seq.py b/tools/int_seq.py index 92b5250..3e00b20 100644 --- a/tools/int_seq.py +++ b/tools/int_seq.py @@ -35,4 +35,4 @@ def pentagonal(n: int) -> int: A pentagonal number is a figurate number that extends the concept of triangular and square numbers to the pentagon 0, 1, 5, 12, 22, 35, ... """ - return ((3 * n * n) - n) / 2 + return ((3 * n * n) - n) // 2 From 210d407bf90e4d4115f8391f3ac6b029affc13aa Mon Sep 17 00:00:00 2001 From: Stefan Harmuth Date: Sun, 7 Aug 2022 19:34:37 +0200 Subject: [PATCH 3/4] remove class variables (should be instance variables) --- tools/coordinate.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/tools/coordinate.py b/tools/coordinate.py index 02f59bc..3609eff 100644 --- a/tools/coordinate.py +++ b/tools/coordinate.py @@ -195,10 +195,6 @@ class Coordinate: class Shape: - top_left: Coordinate - bottom_right: Coordinate - mode_3d: bool - def __init__(self, top_left: Coordinate, bottom_right: Coordinate): """ in 2D mode: top_left is the upper left corner and bottom_right the lower right @@ -211,7 +207,7 @@ class Shape: self.bottom_right = bottom_right self.mode_3d = top_left.z is not None and bottom_right.z is not None - def size(self): + def __len__(self): if not self.mode_3d: return (self.bottom_right.x - self.top_left.x + 1) * (self.bottom_right.y - self.top_left.y + 1) else: From f5d59cd74f9b173e450be9c7f43a396a33ff54ba Mon Sep 17 00:00:00 2001 From: Stefan Harmuth Date: Sun, 7 Aug 2022 19:36:48 +0200 Subject: [PATCH 4/4] cleanup --- tools/coordinate.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tools/coordinate.py b/tools/coordinate.py index 3609eff..de3edc3 100644 --- a/tools/coordinate.py +++ b/tools/coordinate.py @@ -62,7 +62,7 @@ class Coordinate: def getNeighbours(self, includeDiagonal: bool = True, minX: int = -inf, minY: int = -inf, maxX: int = inf, maxY: int = inf, minZ: int = -inf, maxZ: int = inf) -> list[Coordinate]: """ - Get a list of neighbouring coordinates + Get a list of neighbouring coordinates. :param includeDiagonal: include diagonal neighbours :param minX: ignore all neighbours that would have an X value below this @@ -73,7 +73,6 @@ class Coordinate: :param maxZ: ignore all neighbours that would have an Z value above this :return: list of Coordinate """ - neighbourList = [] if self.z is None: if includeDiagonal: nb_list = [(-1, -1), (-1, 0), (-1, 1), (0, -1), (0, 1), (1, -1), (1, 0), (1, 1)]