Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Third solution in Clear category for Numbered Triangles by gyahun_dash
from itertools import chain, islice, permutations as perm, product, starmap
from operator import eq, itemgetter as getter
from functools import partial
ichain = chain.from_iterable
def connect(triangles):
rotate = lambda deg: triangles[deg:] + triangles[: deg]
return all(map(eq, *(map(getter(i), rotate(i)) for i in (0, -1))))
def checkio(chips):
combs = ichain(starmap(product, map(partial(map, perm), perm(chips))))
filtered = filter(connect, islice(combs, 2799360))
sums = set(map(sum, map(partial(map, getter(1)), filtered)))
return max(sums) if sums else 0
Aug. 17, 2014
Comments: