Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Identify Block by brownie57
def identify_block(numbers):
"""
grid(4x4):
+--+--+--+--+
|1 |2 |3 |4 |
+--+--+--+--+
|5 |6 |7 |8 |
+--+--+--+--+
|9 |10|11|12|
+--+--+--+--+
|13|14|15|16|
+--+--+--+--+
blocks(7 kinds):
'I' 'J' 'L' 'O' 'S' 'T' 'Z'
* * * ** ** *** **
* * * ** ** * **
* ** **
*
"""
numbers = sorted(list(numbers))
while min(numbers)>=5:
for i in range(4):
numbers[i] = numbers[i]-4
while 1 not in numbers and 5 not in numbers and 9 not in numbers:
for j in range(4):
numbers[j] = numbers[j]-1
if numbers in [[1,2,3,4],[1,5,9,13]]:
return 'I'
elif numbers == [1,2,5,6]:
return 'O'
elif numbers in [[2,6,9,10],[1,5,6,7],[1,2,5,9],[1,2,3,7]]:
return 'J'
elif numbers in [[1,5,9,10],[1,2,3,5],[1,2,6,10],[3,5,6,7]]:
return 'L'
elif numbers in [[2,3,5,6],[1,5,6,10]]:
return 'S'
elif numbers in [[1,2,6,7],[2,5,6,9]]:
return 'Z'
elif numbers in [[1,2,3,5],[2,5,6,10],[2,5,6,7],[1,5,6,9]]:
return 'T'
else:
return 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"?')
July 1, 2018
Comments: