This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def mprint(): | |
for i in range(ROWS * COLS): | |
print('.X'[i == POS], end=' ') | |
if i and not i % COLS - 1: | |
print() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ROWS = 7 | |
COLS = 7 | |
BOARD = ['.' for x in range(ROWS * COLS)] | |
POS = 9 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
matrix_orig = [matrix[r:r + cols] for r in range(0, len(matrix), cols)] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
rep = '\n'.join([' '.join(map(str, row)) for row in matrix]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for i in range(len(matrix)): | |
print(matrix[i], end=' ') | |
if i and not i % cols - 1: | |
print() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
rows = 9 | |
cols = 1 | |
mget(0, 3) # => 4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
matrix = [i + 1 for i in matrix] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def mget(r, c): | |
return matrix[r * cols + c] | |
mget(2, 1) # => 8 |