Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Numbered Triangles by flpo
from itertools import permutations, chain
def checkio(chips):
def valid_hexagons(candidates):
for used_chip, candidate in candidates:
check_side = (len(candidate) + 1) % 2
if len(candidate) == 6 and candidate[0][check_side] == candidate[-1][check_side]:
yield sum(c[2] for c in candidate)
else:
yield from valid_hexagons(
(used_chip + [i], candidate + [list(p)])
for i, chip in enumerate(chips) for p in set(permutations(chip))
if i not in used_chip and p[check_side] == candidate[-1][check_side]
)
return max(chain([0], valid_hexagons((([0], [[chips[0][(i + j) % 3] for j in range(3)]]) for i in range(3)))))
July 3, 2017
Comments: