Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Functional way solution in Uncategorized category for Spaceship Landing Strip by lezeroq
# migrated from python 2.7
from operator import getitem
from functools import partial
from itertools import permutations
def checkio(field):
types = {'G': 1, 'S': 1, 'R': 0, 'W': 0, 'T': 0}
field = list(map(partial(map, lambda x: types[x]), field))
N, M = len(field), len(field[0])
def nexts(i):
return list(map(lambda x, y: x * (y + 1), field[i], nexts(i - 1))) if i > 0 else field[0]
return max([max([min(l) * len(l) for l in [getitem(a, slice(*x)) for x in [x for x in permutations(list(range(M + 1)), 2) if x[0] < x[1]]]]) for a in list(map(nexts, list(range(N))))])
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')
Oct. 30, 2012
Comments: