Skip to content

Instantly share code, notes, and snippets.

View molarmanful's full-sized avatar
🐉

Ben Pang molarmanful

🐉
View GitHub Profile
def mprint():
for i in range(ROWS * COLS):
print('.X'[i == POS], end=' ')
if i and not i % COLS - 1:
print()
def move_wrap(d):
if d == 'up':
POS = (POS - COLS) % ROWS
if d == 'down':
POS = (POS + COLS) % ROWS
if d == 'left':
POS = POS - 1 if POS % COLS else POS + COLS - 1
if d == 'right':
POS = POS + 1 if (POS + 1) % COLS else POS - COLS + 1
ROWS = 7
COLS = 7
BOARD = ['.' for x in range(ROWS * COLS)]
POS = 9
def move(d):
if d == 'up' and POS - COLS >= 0:
POS -= COLS
if d == 'down' and POS + COLS < ROWS * COLS:
POS += COLS
if d == 'left' and POS % COLS:
POS -= 1
if d == 'right' and (POS + 1) % COLS:
POS += 1
matrix_orig = [matrix[r:r + cols] for r in range(0, len(matrix), cols)]
rep = '\n'.join([' '.join(map(str, row)) for row in matrix])
for i in range(len(matrix)):
print(matrix[i], end=' ')
if i and not i % cols - 1:
print()
rows = 9
cols = 1
mget(0, 3) # => 4
matrix = [i + 1 for i in matrix]
def mget(r, c):
return matrix[r * cols + c]
mget(2, 1) # => 8