Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class PixPix:
- def __init__(self, a, b, c, d):
- self.a, self.b, self.c, self.d = a, b, c, d
- def __mul__(self, x):
- a, b, c, d = self.a, self.b, self.c, self.d
- e, f, g, h = x.a, x.b, x.c, x.d
- if d == e and c == f:
- return PixPix(a, b, g, h)
- def __repr__(self):
- return '[{},{},{},{}]'.format(self.a, self.b, self.c, self.d)
- def __eq__(self, x):
- return (self.a, self.b, self.c, self.d) == (x.a, x.b, x.c, x.d)
- class Maxel:
- def __init__(self, *pixs):
- self.pixs = pixs
- def __add__(self, x):
- return Maxel(self.pixs + x.pixs)
- def __mul__(self, x):
- return Maxel(*(i*j for i in self.pixs for j in x.pixs if i*j is not None))
- def __repr__(self):
- return '[' + ' '.join(map(repr, self.pixs)) + ']'
- def __eq__(self, x):
- if len(self.pixs) != len(x.pixs):
- return False
- a = list(self.pixs)
- b = list(x.pixs)
- while a:
- if a[0] not in b:
- return False
- b.remove(a[0])
- a.remove(a[0])
- return True
- def __pow__(self, n):
- assert n == int(n) and n >= 1
- a = self
- for _ in range(n-1):
- a *= self
- return a
- m = Maxel(PixPix(2,1,1,1), PixPix(2,2,2,1), PixPix(1,1,2,2), PixPix(1,2,1,2))
- """
- >>> m
- [[2,1,1,1] [2,2,2,1] [1,1,2,2] [1,2,1,2]]
- >>> m**4
- [[2,1,1,2] [2,2,2,2] [1,1,1,1] [1,2,2,1]]
- >>> m**4 == (m**4)*(m**4)
- True
- >>> m == m**5
- True
- >>> m**2 == m**4
- False
- >>> [[2*p.a+p.b-2, 2*p.d+p.c-2] for p in m.pixs]
- [[3, 1], [4, 2], [1, 4], [2, 3]]
- Record [3,1] etc in a matrix.
- [0 0 0 1; 0 0 1 0; 1 0 0 0; 0 1 0 0] = [0 -1; 1 0] = i
- """
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement