2014\Province_C_C++_B\7 六角填数
标题:六角填数
如图所示六角形中,填入1~12的数字。
使得每条直线上的数字之和都相同。
图中,已经替你填好了3个数字,请你计算星号位置所代表的数字是多少?
请通过浏览器提交答案,不要填写多余的内容。
Code
Python
import itertools
num = [2, 4, 5, 6, 7, 9, 10, 11, 12]
for solve in list(itertools.permutations(num, len(num))):
solve = list(solve)
solve.insert(0, 1)
solve.insert(1, 8)
solve.insert(11, 3)
if solve[0] + solve[2] + solve[5] + solve[7] == \
solve[1] + solve[2] + solve[3] + solve[4] == \
solve[0] + solve[3] + solve[6] + solve[10] == \
solve[1] + solve[5] + solve[8] + solve[11] == \
solve[4] + solve[6] + solve[9] + solve[11] == \
solve[7] + solve[8] + solve[9] + solve[10]:
print(solve)