Skip to content

Instantly share code, notes, and snippets.

@main--
Last active August 29, 2015 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save main--/f48a3f7dde78702012eb to your computer and use it in GitHub Desktop.
Save main--/f48a3f7dde78702012eb to your computer and use it in GitHub Desktop.
"""
Turn arrays like this:
+-0°/360° just print normally
90°/-270° swap X and Z offsets and reverse iteration direction of inner loop
180°/-180° reverse both X and Z iteration direction (downwards; start from high corner)
270°/-90° swap X and Z offsets and reverse iteration direction of outer loop
"""
data = [['0', '1', '2', '3'], ['4', '5', '6', '7'], ['8', '9', 'a', 'b']]
def build(iter):
board = [[' ' for x in range(4)] for x in range(4)]
for (dx, dz), (tx, tz) in zip(iterstd(), iter):
board[tx][tz] = data[dx][dz]
for line in board:
for ele in line:
print(ele, end='')
print()
def iterstd():
for x in range(0, 3):
for z in range(0, 4):
yield x, z
def iterreverse():
for x in range(2, -1, -1):
for z in range(3, -1, -1):
yield x, z
def iter90():
for x in range(2, -1, -1):
for z in range(0, 4):
yield z, x
def iterp90(): #GeT_PrO90 #hashtag
for x in range(0, 3):
for z in range(3, -1, -1):
yield z, x
print('\tNormal:')
build(iterstd())
print('\t+90°')
build(iter90())
print('\t+180°')
build(iterreverse())
print('\t+270°')
build(iterp90())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment