Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Straightforward solution in Clear category for Identify Block by martin_b
def identify_block(numbers):
# define the lettes
letters = {
(0, 4, 8, 12): 'I',
(1, 5, 8, 9): 'J',
(0, 4, 8, 9): 'L',
(0, 1, 4, 5): 'O',
(1, 2, 4, 5): 'S',
(0, 1, 2, 5): 'T',
(0, 1, 5, 6): 'Z'
}
# normalize - move the letter to the top left corner
def normalize(b):
m = (min(b) // 4) * 4 + min(x % 4 for x in b)
return tuple(x - m for x in sorted(b))
# normalize the input
numbers = normalize([x - 1 for x in numbers])
for block, letter in letters.items():
# get grid from the letter numbers
grid = [1 if i in block else 0 for i in range(16)]
grid = tuple(tuple(grid[i:i + 4]) for i in range(0, 16, 4))
# compare the input to the 4 rotations of the letter
for i in range(4):
# compare the grid to the normalized numbers
g = sum(grid, ())
if numbers == normalize([i for i in range(16) if g[i]]):
return letter
# rotate grid
grid = tuple([r for r in zip(*grid)][::-1])
Oct. 28, 2017
Comments: