Skip to content

Commit

Permalink
Update sketch_2024_12_10.py
Browse files Browse the repository at this point in the history
  • Loading branch information
villares committed Dec 11, 2024
1 parent f94fca7 commit aac4b55
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions 2024/sketch_2024_12_10/sketch_2024_12_10.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from itertools import permutations
import py5
import numpy as np

Expand All @@ -14,7 +15,7 @@ def setup():
grids.append(grids[-1].rotated90())
#grids.append(grids[-1].alternate())

#for g in set(grids):
#for g in set(grids): # testing for duplicate removal
for g in grids:
g.draw()
py5.translate(Grid.CS * (g.order + 1), 0)
Expand All @@ -41,17 +42,21 @@ def alternate(self):

def __eq__(self, other):
return hash(self) == hash(other)

def __hash__(self):
"""
Makes rotations equivalent.
Makes rotations and different colors equivalent.
"""
h = hash(self.array.tobytes())
s = self
for _ in range(3):
s = s.rotated90()
h = min(h, hash(s.array.tobytes()))
return(h)
a = self.array
h = hash(a.tobytes())
values, inverse_indices = np.unique(a, return_inverse=True)
for vs in permutations(values):
a = np.array(vs)[inverse_indices].reshape(self.order, self.order)
h = min(h, hash(a.tobytes()))
for _ in range(3):
a = np.rot90(a, 1)
h = min(h, hash(a.tobytes()))
return h

def draw(self):
rows, cols = self.array.shape
Expand Down

0 comments on commit aac4b55

Please sign in to comment.