Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
horribly slow, brute force solution in Clear category for Numbered Triangles by ssk8
from itertools import permutations, chain
arrange = {i:chip for i, chip in enumerate(permutations(range(3)))}
key = [(0, 17), (2, 3), (5, 6), (8, 9), (11, 12), (14, 15)]
combos = []
[[[[[[combos.append((a, b, c, d, e, f)) for a in range(6)] for b in range(6)] for c in range(6)] for d in range(6)] for e in range(6)] for f in range(6)]
def checkio(chips):
total = 0
high = sum([max(chip) for chip in chips])
for this_order in permutations(chips):
for this_arrangement in combos:
current = [[chip[n] for n in arrange[this_arrangement[i]]] for i, chip in enumerate(this_order)]
flat = list(chain.from_iterable(current))
if all([flat[k[0]] == flat[k[1]] for k in key]):
current_total = sum([flat[i] for i in (1, 4, 7, 10, 13, 16)])
if current_total == high: return high
if current_total > total:
total = current_total
return total
#These "asserts" using only for self-checking and not necessary for auto-testing
if __name__ == '__main__':
assert checkio(
[[1, 4, 20], [3, 1, 5], [50, 2, 3],
[5, 2, 7], [7, 5, 20], [4, 7, 50]]) == 152, "First"
assert checkio(
[[1, 10, 2], [2, 20, 3], [3, 30, 4],
[4, 40, 5], [5, 50, 6], [6, 60, 1]]) == 210, "Second"
assert checkio(
[[1, 2, 3], [2, 1, 3], [4, 5, 6],
[6, 5, 4], [5, 1, 2], [6, 4, 3]]) == 21, "Third"
assert checkio(
[[5, 9, 5], [9, 6, 9], [6, 7, 6],
[7, 8, 7], [8, 1, 8], [1, 2, 1]]) == 0, "Fourth"
Aug. 5, 2018