|
MATHEMATICA
|
For[n = 1, n <= 5, n++,
cnt = 0;
For[ii = 0, ii <= 2^(n^2), ii++,
A = Partition[IntegerDigits[ii, 2, n^2], n];
G = EmptyGraph[n^2];
deleteG = 0;
vert = {0, -1};
horiz = {-1, 0};
For[i = 1, i <= n, i++,
For[j = 1, j <= n, j++,
If[A[[i, j]] == 1,
For[k = 1, k <= 2, k++,
If[A[[i + vert[[k]], j + horiz[[k]]]] == 1,
G = AddEdge[G, {j + (i - 1) n, j + horiz[[k]] + (i - 1) n + n vert[[k]]}];
]
],
deleteG++;
]
]
];
CC = ConnectedComponents[G];
cnt += (Length[CC] - deleteG);
];
Print[cnt]
|