Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Identify Block solution in Clear category for Identify Block by tssrkt777
def clean_slepok(slepok):
while sum(slepok[0])==0:
del slepok[0]
while sum(slepok[-1])==0:
del slepok[-1]
return [list(x) for x in slepok]
def patterns(slepok):
PATTERNS = {
'I': [[1], [1], [1], [1]],
'J': [[0, 1], [0, 1], [1, 1]],
'L': [[1, 0], [1, 0], [1, 1]],
'O': [[1, 1], [1, 1]],
'S': [[0, 1, 1], [1, 1, 0]],
'T': [[1, 1, 1], [0, 1, 0]],
'Z': [[1, 1, 0], [0, 1, 1]]
}
for y in range(4):
for k, v in PATTERNS.items():
if v == slepok:
return k
slepok = [list(x) for x in list(zip(*slepok[::-1]))]
def identify_block(nums):
gen = iter(range(1, 17))
m = [[next(gen) for _ in range(4)] for _ in range(4)]
slepok = [[int(x in nums) for x in y] for y in m]
slepok = clean_slepok(slepok)
slepok = clean_slepok(list(zip(*slepok[::-1])))
return patterns(slepok)
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. 20, 2021
Comments: