Problem 68

completed February 1, 2012

Comments

I found this one to be much easier than I expected it to be. It was intimidating because of the geometric shapes involved. However, by simply numbering each node, the problem because easily workable.

I took all permutations of the numbers 1 through 10 and subjected them to three tests. First, whether each line in the ring summed to the same number. Second, whether what I considered the top most node was in fact that with the lowest integer assignment. Finally, whether the concatenation was 16-digits in length.

Results

With this, the script ran in 3 seconds.

Code

from itertools import *

works = set()
prev = 'I love Peter and Charlie'

for t in permutations(range(1,11)):
	if t[0]+t[1]+t[2] == t[3]+t[2]+t[4] == t[5]+t[4]+t[6] == t[7]+t[6]+t[8] == t[9]+t[8]+t[1]:
		if t[0] < t[3] and t[0] < t[5] and t[0] < t[7] and t[0] < t[9]:
			new = ''.join(map(str, [t[0],t[1],t[2],t[3],t[2],t[4],t[5],t[4],t[6],t[7],t[6],t[8],t[9],t[8],t[1]]))
			if len(new) == 16:
				works.add(new)

print max(works)