数独九宫格转一维数组算法代码片段

@Slf4j
public class Test {
    public static void main(String[] args) {
//        calc(18);
        for (int i = 0; i < 81; i++) {
            calc(i);
        }
    }

    public static void calc(int i) {
        int x = i%9;
        int y = i/9;
//        log.info("x={},y={}", x, y);
        int out = x / 3 + 1 + y / 3 * 3;
        int in = x % 3 + 1 + y % 3 * 3;
//        log.info("out={},in={}", out, in);
        log.info("i={},id={}-{}", i, out, in);
    }

}

觉得内容还不错?打赏个钢镚鼓励鼓励!!👍