A333466等
Graphillion を使って計算してみた。
from graphillion import GraphSet
import graphillion.tutorial as tl
def four_corners(n):
return [1, n, n * (n - 1) + 1, n * n]
def points_on_diagonal_1(n):
return [i + 1 for i in range(n * n) if i % n - i // n == 0]
def points_on_diagonal_2(n):
return [i + 1 for i in range(n * n) if i % n + i // n == n - 1]
def points_on_two_diagonals(n):
return [i + 1 for i in range(n * n) if i % n - i // n == 0 or i % n + i // n == n - 1]
def A(points, n):
print(points)
universe = tl.grid(n - 1, n - 1)
GraphSet.set_universe(universe)
cycles = GraphSet.cycles()
for i in points:
cycles = cycles.including(i)
return cycles.len()
print([A(four_corners(n), n) for n in range(2, 10)])
print([A(points_on_diagonal_1(n), n) for n in range(2, 10)])
print([A(points_on_diagonal_2(n), n) for n in range(2, 10)])
print([A(points_on_two_diagonals(n), n) for n in range(2, 10)])
出力結果
[1, 2, 3, 4]
[1, 3, 7, 9]
[1, 4, 13, 16]
[1, 5, 21, 25]
[1, 6, 31, 36]
[1, 7, 43, 49]
[1, 8, 57, 64]
[1, 9, 73, 81]
[1, 1, 11, 373, 44930, 17720400, 22013629316, 84579095455492]
[1, 4]
[1, 5, 9]
[1, 6, 11, 16]
[1, 7, 13, 19, 25]
[1, 8, 15, 22, 29, 36]
[1, 9, 17, 25, 33, 41, 49]
[1, 10, 19, 28, 37, 46, 55, 64]
[1, 11, 21, 31, 41, 51, 61, 71, 81]
[1, 2, 22, 716, 73346, 23374544, 23037365786, 69630317879888]
[2, 3]
[3, 5, 7]
[4, 7, 10, 13]
[5, 9, 13, 17, 21]
[6, 11, 16, 21, 26, 31]
[7, 13, 19, 25, 31, 37, 43]
[8, 15, 22, 29, 36, 43, 50, 57]
[9, 17, 25, 33, 41, 49, 57, 65, 73]
[1, 2, 22, 716, 73346, 23374544, 23037365786, 69630317879888]
[1, 2, 3, 4]
[1, 3, 5, 7, 9]
[1, 4, 6, 7, 10, 11, 13, 16]
[1, 5, 7, 9, 13, 17, 19, 21, 25]
[1, 6, 8, 11, 15, 16, 21, 22, 26, 29, 31, 36]
[1, 7, 9, 13, 17, 19, 25, 31, 33, 37, 41, 43, 49]
[1, 8, 10, 15, 19, 22, 28, 29, 36, 37, 43, 46, 50, 55, 57, 64]
[1, 9, 11, 17, 21, 25, 31, 33, 41, 49, 51, 57, 61, 65, 71, 73, 81]
[1, 0, 6, 68, 6102, 1404416, 1094802826, 2524252113468]
0 件のコメント:
コメントを投稿
注: コメントを投稿できるのは、このブログのメンバーだけです。