Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Numbered Triangles by mozurin
def checkio(chips):
start = chips[0]
remains = chips[1:]
def findNextChip(from_, to, used):
found = []
for rn in set(range(len(remains))) - used:
try:
fromPos = remains[rn].index(from_)
except ValueError:
continue
l, r = remains[rn][:fromPos] + remains[rn][fromPos + 1:]
if len(used) == len(remains) - 1:
if l == to:
found.append((r,))
elif r == to:
found.append((l,))
else:
found.extend(
(outer,) + chain
for nextFrom, outer in ((l, r), (r, l))
for chain in findNextChip(nextFrom, to, used | set([rn]))
)
return found
candidates = [0]
for rotation in range(3):
base, from_, to = start[rotation:] + start[:rotation]
candidates.extend(
sum(pattern) + base for pattern in findNextChip(from_, to, set())
)
return max(candidates)
May 21, 2017