I am new to Erlang and trying to make a Sudoku solver. So far I can have an input consisting of a list of 81 integers (9x9) like this
sudoku() -> [6,7,1,8,2,3,4,9,5,5,4,9,1,7,6,3,2,8,3,2,8,5,4,9,1,6,7,1,3,2,6,5,7,8,4,9,9,8,6,4,1,2,5,7,3,4,5,7,3,9,8,6,1,2,8,9,3,2,6,4,7,5,1,7,1,4,9,3,5,2,8,6,2,6,5,7,8,1,9,3,4].
That I split into rows based on the list splitting algorithm by stemm:
[5,4,9,1,7,6,3,2,8], [3,2,8,5,4,9,1,6,7], [1,3,2,6,5,7,8,4,9], [9,8,6,4,1,2,5,7,3], [4,5,7,3,9,8,6,1,2], [8,9,3,2,6,4,7,5,1], [7,1,4,9,3,5,2,8,6], [2,6,5,7,8,1,9,3,4]]
To obtain the columns I just transpose this matrix with the elegant solution of mpm.
The next step is to collect lists of the nine square boxes. Then I can check if there are duplicate elements in those lists to see if a solution is valid.
Unfortunately I have no clear idea how to obtains the squares, e.g.,
[,,, ,,, ,,]
where each square represents the nine numbers in the block. So square one in this case looks like this:
[5,4,9, 3,2,8, 1,2,2]
Does anyone have an idea how to do this?