Skip to content

Instantly share code, notes, and snippets.

@Robert-trober
Last active July 21, 2023 18:34
Show Gist options
  • Save Robert-trober/fb4d2904ac48aa1ff170bb77903beaf4 to your computer and use it in GitHub Desktop.
Save Robert-trober/fb4d2904ac48aa1ff170bb77903beaf4 to your computer and use it in GitHub Desktop.
Creates 'codes' for 2-d polythings
def main():
shape = [[0, 0, 1, 1, 1],
[0, 0, 1, 0, 1],
[1, 1, 1, 1, 1],
[1, 1, 1, 0, 1],
[0, 0, 1, 1, 1]]
rowlim = 4
collim = 4
total = 0
for r in shape:
for i in r:
total += i
print(total, "total")
# print("\033[94m {}\033[00m".format())
def lister(x, y):
n = 0
count = 0
ring = 1
blub = []
while count < total-1:
n += 1
num = 0
for ljk in range(4):
ljk += 1
stuff = checker(ljk, x, y, ring, n)
count += stuff
num += stuff
blub.append(num)
#print(num, "num")
#print("\033[95m {}\033[00m".format(blub))
if n == 2*ring:
ring += 1
n = 0
if n > 10:
exit()
return blub
# 1 up 2 right 3 down 4 left
lst = [["idk"], [1, 1, -1], [-1, 1, 1], [-1, -1, 1], [1, -1, -1]]
def checker(dr, x, y, t, d):
#print(dr, "direction")
#print(d, "n")
if dr == 1 or dr == 3:
y = y+lst[dr][2]*t
if d != 1:
if d-1 <= t:
xis = x + (lst[dr][0] * (d-1))
yis = y
else:
xis = x + (lst[dr][0] * t)
yis = y + (lst[dr][1] * (d-t-1))
else:
xis = x; yis = y
else:
x = x+lst[dr][2]*t
if d != 1:
if d-1 <= t:
yis = y + (lst[dr][1] * (d-1))
xis = x
else:
yis = y + (lst[dr][1] * t)
xis = x + (lst[dr][0] * (d-t-1))
else:
xis = x; yis = y
#z = (x, y, "x and y")
#print("\033[94m {}\033[00m".format(z))
#z = (xis, yis, "coordinates ")
#print("\033[92m {}\033[00m".format(z))
if xis < 0 or xis > rowlim or yis < 0 or yis > collim:
j = 0
else:
j = shape[yis][xis]
#print(shape[yis][xis], "result")
return j
row = -1
final = []
for r in shape:
row += 1
column = -1
for i in r:
column += 1
if i == 1:
#print(row, column, "column and row")
ting = lister(column, row)
print(ting, row, column)
if len(ting) > len(final):
m = len(ting)-len(final)
for i in range(m):
final.append(0)
m = len(ting)
for i in range(m):
final[i] += ting[i]
#print(final)
print("Final 'code' for the shape inputted:")
print("\033[96m {}\033[00m".format(final))
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment