Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
__ solution in Clear category for Numbered Triangles by Cjkjvfnby
from itertools import permutations
# triangle schema: start, end, val
def count_sum(block, triangles):
start, end, val = block
if not triangles:
return val
has_matches = (x for x in triangles if end in x) # filter out not matching triangles
result = []
for match in has_matches:
for tr_start, tr_end, tr_summ in permutations(match):
if tr_start == end and (len(triangles) != 1 or tr_end == start):
new_triangles = list(triangles)
new_triangles.remove(match)
result.append(count_sum((start, tr_end, val + tr_summ), new_triangles))
return len(result) and max(result)
def checkio(chips):
first, *triangles = chips
return max(count_sum(x, triangles) for x in permutations(first))
March 10, 2014
Comments: