Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Creative category for Identify Block by Sim0000
table = {
((0, 0), (1, 0), (2, 0), (3, 0)) : 'I',
((0, 0), (0, 1), (0, 2), (0, 3)) : 'I',
((0, 0), (1, 0), (2, -1), (2, 0)) : 'J',
((0, 0), (1, 0), (1, 1), (1, 2)) : 'J',
((0, 0), (0, 1), (1, 0), (2, 0)) : 'J',
((0, 0), (0, 1), (0, 2), (1, 2)) : 'J',
((0, 0), (1, 0), (2, 0), (2, 1)) : 'L',
((0, 0), (0, 1), (0, 2), (1, 0)) : 'L',
((0, 0), (0, 1), (1, 1), (2, 1)) : 'L',
((0, 0), (1, -2), (1, -1), (1, 0)): 'L',
((0, 0), (0, 1), (1, 0), (1, 1)) : 'O',
((0, 0), (0, 1), (1, -1), (1, 0)) : 'S',
((0, 0), (1, 0), (1, 1), (2, 1)) : 'S',
((0, 0), (0, 1), (0, 2), (1, 1)) : 'T',
((0, 0), (1, -1), (1, 0), (2, 0)) : 'T',
((0, 0), (1, -1), (1, 0), (1, 1)) : 'T',
((0, 0), (1, 0), (1, 1), (2, 0)) : 'T',
((0, 0), (0, 1), (1, 1), (1, 2)) : 'Z',
((0, 0), (1, -1), (1, 0), (2, -1)): 'Z',
}
def identify_block(numbers):
def normalize(p2, p1):
y1, x1 = divmod(p1 - 1, 4)
y2, x2 = divmod(p2 - 1, 4)
return (y2 - y1, x2 - x1)
org = min(numbers)
normalized_numbers = tuple(sorted(normalize(p, org) for p in numbers))
return table.get(normalized_numbers, None)
if __name__ == '__main__':
#These "asserts" using only for self-checking and not necessary for auto-testing
assert identify_block({10, 13, 14, 15}) == 'T', 'T'
assert identify_block({1, 5, 9, 6}) == 'T', 'T'
assert identify_block({2, 3, 7, 11}) == 'L', 'L'
assert identify_block({4, 8, 12, 16}) == 'I', 'I'
assert identify_block({3, 1, 5, 8}) == None, 'None'
print('"Run" is good. How is "Check"?')
Oct. 18, 2017
Comments: