Recursive solution to Sudoku generator

后端 未结 6 960
青春惊慌失措
青春惊慌失措 2020-12-19 05:14

I\'m trying to code an algorithm that creates a legal Sudoku board in either Java or Javascript. Neither work, and I\'m not entirely sure why.

Essentially, the prob

6条回答
  •  渐次进展
    2020-12-19 06:05

    interesting question, I just noticed this one bug in the Java code: isn't the call to Collection.shuffle() useless since the toCheck array will remain unmodifed (unshuffled) after this call? Here is my quick fix (and I'm sure there are more clever ways to do it):

    List lst = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9);
    Collections.shuffle(lst);
    for (int i=0; i

提交回复
热议问题