Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Uncategorized category for Spaceship Landing Strip by Avaris
# migrated from python 2.7
import itertools
def checkio(map):
m = len(map)
n = len(map[0])
result = 0
for i, j in itertools.product(list(range(m)), list(range(n))):
if map[i][j] not in 'GS':
continue
for ii, jj in itertools.product(list(range(i+1, m+1)), list(range(j+1, n+1))):
area = ''.join(row[j:jj] for row in map[i:ii])
if all(c in 'GS' for c in area):
result = max(result, len(area))
return result
if __name__ == '__main__':
assert checkio(['G']) == 1, 'First'
assert checkio(['GS','GS']) == 4, 'Second'
assert checkio(['GT','GG']) == 2, 'Third'
assert checkio(['GGTGG','TGGGG','GSSGT','GGGGT','GWGGG','RGTRT','RTGWT','WTWGR']) == 9, 'Fourth'
print('All is ok')
Nov. 4, 2012
Comments: