Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Spaceship Landing Strip by makoto_yamagata
from itertools import groupby
def checkio(landing_map):
def max_seqbits(v):
return max([sum(map(int, x)) for n, x in groupby(format(v, 'b'))])
trans = str.maketrans('GSTRW', '11000')
xs = [int(x.translate(trans), 2) for x in landing_map]
result = 0
for i in range(len(xs)):
val = xs[i]
for n, j in enumerate(range(i, len(xs))):
val &= xs[j]
result = max(result, max_seqbits(val) * (n+1))
return result
if __name__ == '__main__':
#These "asserts" using only for self-checking and not necessary for auto-testing
assert checkio(['G']) == 1, 'One cell - one variant'
assert checkio(['GS',
'GS']) == 4, 'Four good cells'
assert checkio(['GT',
'GG']) == 2, 'Four cells, but with a tree'
assert checkio(['GGTGG',
'TGGGG',
'GSSGT',
'GGGGT',
'GWGGG',
'RGTRT',
'RTGWT',
'WTWGR']) == 9, 'Classic'
March 18, 2014