我正在尝试创建一个方法,它将从我生成的已解决的Sudoku矩阵中删除每一行中的一个随机元素。我怎么能做到这一点?
Solved Sudoku Generator:
public static void generate_Sud (int n, int [][] S){ // Generates Sudoku method
for (int r=0; r<=n-1; r++){
int startNum = (int) (Math.sqrt(n) * (r % Math.sqrt(n)) + (r/Math.sqrt(n)));
for (int c=0; c<=n-1; c++){
S[r][c] = ((startNum + c) % n) + 1;
}
}
}
答案 0 :(得分:0)
对于3x3 Sodoku:
for(int i = 0; i < 3; i++){
int randomPosition = (int) Math.floor(Math.random() * 3) //Random number between 0 and 2
S[i][randomPosition] = -1; // -1 or whatever you use to represent blank
}