forked from KenMercusLai/checkio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Spaceship landing strip.py
27 lines (26 loc) · 1.11 KB
/
Spaceship landing strip.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
def checkio(landing_map):
new_map = [(i.replace('G', '1').replace('S', '1').replace('R', '0').
replace('W', '0').replace('T', '0'))
for i in landing_map]
columns = len(new_map[0])
rows = len(new_map)
maxsize = 0
for y in xrange(rows):
for x in xrange(columns):
for y2 in xrange(y, rows):
for x2 in xrange(x, columns):
if (abs(y - y2) + 1) * (abs(x - x2) + 1) <= maxsize:
continue
else:
sub_map_string = ''.join([new_map[i][x:x2 + 1]
for i in xrange(y, y2 + 1)])
if '0' not in sub_map_string:
maxsize = sub_map_string.count('1')
return maxsize
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'