Created a fast and dirty python script that lists all distinct patterns in an n x k bounding box, which is minimal rectangular container for the listed patterns. Slow and unoptimized, reviews, opinions are welcome!
- Independent from golly
- Self-explanatory the usage
- Run without arguments to see brief intructions!
Code: Select all
C:\TEMP\WINDOWS>python rectanglefiller.py 3 2 > savedrle.txt
Code: Select all
#!/usr/bin/env python
# NASZVADI P, 2017-02-*
# Some right reversed
# Do NOT violate the laws of the authot's country!
# No commercial use!
import re
import sys
def torle(a):
b = str(a)[:-1].replace('1','o').replace('0','b').replace(']','$')+'!'
b = re.sub(r'[^bo$!]','',b)
b = re.sub(r'b+\$','$',b)
b = re.sub(r'\$+!','!',b)
e = d = ''
f = 0
for c in b:
if d == c:
f = f + 1
else:
e = e + (str(f) if f > 1 else '')
e = e + d
d = c
f = 1
if c == '!':
e = e + '!'
return e
def main(argv):
maxx, maxy = 0, 0
try:
maxx, maxy = map(lambda x: int(x), argv[:2])
assert len(argv) == 2
assert maxx >= maxy
assert maxy > 0
except:
print '''
ERROR!
Usage:
rectanglefiller <X> <Y>
- X and Y are positive integers
- X >= Y
Output: rle list of all X*Y cell patterns
'''
sys.exit(1)
upperlimit = 1<<(maxx*maxy)
maxxhalf = maxx//2
maxyhalf = maxy//2
for space in range(upperlimit):
basematrix = map(lambda x:int(x), list(str(bin(upperlimit+space))[3:]))
idemp = [basematrix[j*maxx:j*maxx+maxx] for j in range(maxy)]
flipp = [basematrix[j*maxx-maxx:j*maxx] for j in range(maxy,0,-1)]
idemptr = [basematrix[i::maxx] for i in range(maxx)]
flipptr = [basematrix[i-1::maxx] for i in range(maxx,0,-1)]
diag1 = [idemp[i][i:] for i in range(maxx)] if maxx == maxy else 2
diag2 = [idemptr[i][i:] for i in range(maxx)] if maxx == maxy else 2
if \
1 in idemp[0] \
and 1 in flipp[0] \
and 1 in idemptr[0] \
and 1 in flipptr[0] \
and ((idemp[:maxyhalf] >= flipp[:maxyhalf]) and (idemptr[:maxxhalf] >= flipptr[:maxxhalf])) \
and (diag1 >= diag2) \
:
print torle(idemp)
if __name__ == "__main__":
main(sys.argv[1:])
Well, there is at least one - classifying small patterns here ../forums/viewtopic.php?f=11&t=2233#p38503