Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from copy import deepcopy
- def partition(coll, n):
- p = []
- for i in range(0, len(coll), n):
- p.append(coll[i:i+n])
- return p
- def gen_coords(side):
- h = int(side / 2)
- s = [cell for cell in range(-1 * h, h + 1) if cell != 0]
- return [(y, x) for x in s for y in s]
- def make_square(side, letters):
- ks = gen_coords(side)
- return {k : {'letter' : l, 'marked' : False}
- for k, l in zip(ks, letters)}
- def turn(clockwise, coords):
- y = coords[0]
- x = coords[1]
- return (-x, y) if clockwise else (x, -y)
- def turn_lattice(cwise, s):
- new_s = deepcopy(s)
- for k in s.keys():
- new_k = turn(cwise, k)
- new_s[new_k]['marked'] = s[k]['marked']
- return new_s
- def cell2str(v):
- return '▓' if v['marked'] else str(v['letter'])
- def square2str(s, side):
- symbs = [cell2str(v) for v in s.values()]
- matrix = reversed(partition(symbs, side))
- return '\n'.join([' '.join(line) for line in matrix])
- def handle_input():
- uinp = input().split(',')
- return uinp[0] if len(uinp) == 1 else (int(uinp[0]), int(uinp[1]))
- def invert_mark(s, coords):
- new_s = deepcopy(s)
- new_s[coords]['marked'] = not new_s[coords]['marked']
- return new_s
- def main(letters, side):
- square = (make_square(side, letters))
- while True:
- u = handle_input()
- if u == 't':
- square = turn_lattice(True, square)
- elif u == 'T':
- square = turn_lattice(False, square)
- else:
- square = invert_mark(square, u)
- print(square2str(square, side))
- letters = sum([list(range(10)) for _ in range(10)], [])
- main(letters, 10)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement