Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
13-liner: any k-size square grid solution in Clear category for Identify Block by przemyslaw.daniel
BLOCKS = {'I': [0, 1, 2, 3], 'J': [0, 1, 2, 2+1j],
'L': [0, 1j, 2j, 1+2j], 'O': [0, 1j, 1, 1+1j],
'S': [1j, 1, 1+1j, 2], 'T': [0, 1, 1+1j, 2],
'Z': [0, 1, 1+1j, 2+1j]}
def identify_block(numbers, k=4):
numbers = [complex(*divmod(i-1, k)[::-1]) for i in numbers]
for block, pieces in BLOCKS.items():
for _ in range(4):
numbers = [k-1+i*1j for i in numbers] # rotate
numbers = sorted(numbers, key=lambda x: (x.real, x.imag))
if len({x-y for x, y in zip(numbers, pieces)}) == 1:
return block
Sept. 7, 2017
Comments: