Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
O(N), where N is number of cubes solution in Speedy category for The Tower by David_Jones
from collections import defaultdict
rotated = lambda s: s[1:] + s[0]
def tower(cubes):
c = defaultdict(int)
for cube in cubes:
front, right, left, back, top, bottom = cube
for four_sides in (right+top+left+bottom,
front+bottom+back+top,
front+right+back+left):
reversed_four_sides = four_sides[::-1]
c[four_sides] += 1
c[reversed_four_sides] += 1
for _ in range(3):
four_sides = rotated(four_sides)
reversed_four_sides = rotated(reversed_four_sides)
c[four_sides] += 1
c[reversed_four_sides] += 1
return max(c.values())
May 12, 2019