# 纸牌三角形and九宫幻方一些对称数组图形关于旋转和镜像的一些规律总结

①纸牌三角形
②九宫幻方

import java.util.Arrays;

public class Two {
static int cnt = 0;
public static void main(String[] args) {
do {
int sum1 = Arrays[0] + Arrays[1] + Arrays[2] + Arrays[3];
int sum2 = Arrays[3] + Arrays[4] + Arrays[5] + Arrays[6];
int sum3 = Arrays[7] + Arrays[8] + Arrays[6] + Arrays[0];
if (sum1==sum2&&sum2==sum3) {
cnt++;
}
} while (next_permutation(Arrays));
System.out.println(cnt/6);
}
// 方法一 使用 next_permutation
public static void swap(int nums[], int left, int right) {
int t = nums[left];
nums[left] = nums[right];
nums[right] = t;
}
public static void reverse(int nums[], int left, int right) {

while (left < right) {
swap(nums, left++, right--);
}
}
public static boolean next_permutation(int nums[]) {
for (int i = nums.length - 2; i >= 0; i--) {
if (nums[i] < nums[i + 1]) {
for (int j = nums.length - 1; j > i; j--) {
if (nums[j] > nums[i]) {
swap(nums, i, j);
reverse(nums, i + 1, nums.length - 1);
return true;
}
}
}
}
return false;
}
static int Arrays[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
}

04-16 1万+
02-14 1152

09-23 765
03-31 462
04-14 263
05-11 870
02-22 206
07-29 1万+
05-12 5502
04-10 393
03-08 1963
03-28 360
03-04 177
11-18 1万+
03-13 1347