Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Product landing solution in Clear category for Spaceship Landing Strip by hanpari
from itertools import product
def checkio(area):
width, height = len(area[0]), len(area)
good_land = set("GS")
results = {0}
for x,y in product(range(width, 0, -1),
range(height, 0, -1)):
if max(results) >= x * y:
continue
for x_start, y_start in product(range(width - x + 1),
range(height - y + 1)):
if all(area[y_pos][x_pos] in
good_land for
x_pos, y_pos in
product(range(x_start, x_start + x),
range(y_start, y_start + y))):
results.add(x * y)
break
return max(results)
## IMPORTANT LINES DESCRIPTION
## 6. Creating rectangles from the biggest to the smallest ones
## 8. If size (x * y) of rectangles is already in results, just continue
## 10. Shift rectangle in all possible positions
## 12. If rectangle contains only G or S, add its size to results
## 18. Skip to another size, this one is not necessary to evaluate anymore
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'
Aug. 21, 2014
Comments: