Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
itertools.product and np.rot90 solution in 3rd party category for Identify Block by Stensen
import numpy as np
from itertools import product
BLOCKS = {
'T': {(0, 0), (0, 1), (0, 2), (1, 1)},
'I': {(0, 0), (1, 0), (2, 0), (3, 0)},
'O': {(0, 0), (0, 1), (1, 0), (1, 1)},
'L': {(0, 0), (1, 0), (2, 0), (2, 1)},
'J': {(0, 1), (1, 1), (2, 0), (2, 1)},
'S': {(0, 1), (0, 2), (1, 0), (1, 1)},
'Z': {(0, 0), (0, 1), (1, 1), (1, 2)}}
def identify_block(nums):
g = np.arange(1, 17).reshape((4, 4))
for (n, c), r in product(BLOCKS.items(), range(4)):
g = np.rot90(g)
t = {(x, y) for x, y in product(range(4), repeat=2) if g[x, y] in nums}
if len(set((i[0]-j[0], i[1]-j[1]) for i,j in zip(sorted(c), sorted(t))))==1: return n
Sept. 24, 2020