Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
10-liner (clear & speedy) solution in Clear category for The Tower by Merzix
from itertools import permutations
def tower(cubes):
faces = {} # cube: list(frozenset(opposite faces of the cube))
pairs = {} # 2 pairs of opposite faces of the cube : count cubes with such pairs
for cube in cubes:
if cube not in faces:
faces[cube] = list(frozenset((cube[x], cube[y])) for x, y in [(0, 3), (1, 2), (4, 5)])
for face_pair in permutations(faces[cube], 2):
pairs[face_pair] = pairs.get(face_pair, 0) + 1
return max(pairs.values())
if __name__ == '__main__':
assert tower(['GYVABW', 'AOCGYV', 'CABVGO', 'OVYWGA']) == 3
assert tower(['ABCGYW', 'CAYRGO', 'OCYWBA', 'ACYVBR', 'GYVABW']) == 1
assert tower(['GYCABW', 'GYCABW', 'GYCABW', 'GYCABW', 'GYCABW']) == 5
Sept. 29, 2018