d.hatena.ne.jp
を参考に作ってみたのですが結果が違う
target = (12, 20, 25, 32, 37) n = 0 for x1 in range(1, 41): for x2 in range(x1, 41): for x3 in range(x2, 41): for x4 in range(x3, 41): for i in target: flag = False for a1 in (-1, 0, 1): for a2 in (-1, 0, 1): for a3 in (-1, 0, 1): for a4 in (-1, 0, 1): sum = x1 * a1 + x2 * a2 + x3 * a3 + x4 * a4 if sum == i: flag = True else: if not flag: break else: n += 1 print(x1, x2, x3, x4) print(n)
1 2 7 22
1 2 8 22
1 2 9 26
1 3 6 22
1 3 7 21
1 3 7 22
1 3 7 23
1 3 8 20
1 3 8 21
1 3 8 22
省略
27 30 32 37
27 30 32 39
27 30 37 39
27 31 32 38
27 32 32 39
27 32 33 40
27 32 34 39
27 32 37 39
28 32 33 40
28 32 35 40
6482
(12, 20, 25, 32, 27)から(12, 20, 25, 32, 37)に変更しました。
1 2 9 26
1 2 9 31
1 2 11 23
1 2 11 34
1 2 12 22
1 2 12 23
1 2 12 34
1 2 12 35
1 2 13 22
1 2 13 35
省略
27 31 32 38
27 32 32 39
27 32 34 39
27 32 37 39
28 29 32 37
28 29 32 40
28 29 37 40
28 32 33 40
28 32 35 40
28 32 37 40
6304