Backtracking in Erlang -
Sorry for my english first.
I would like to use a back-tracking algorithm in Erlang. This will work as an estimate to solve partially filled sudos. A 9x9 sudoku is stored as a list of 81 elements, where each element stores the potential number that can go to the cell.
My initial solution for 4x4 sudoku looks like this: [[1], [3], [2], [4], [4], [2], [3], [1 ], [2,3], [4], [1], [2,3], [2, 3], [1], [4], [2,3]]
There are 2 solutions in Sudoku. I have to write both of them after reaching the initial solution, I need to implement a back-tracking algorithm, but I do not know how to do it.
I think that the fixed elements are written in a new list called Fixedlist which will change [], [3], [2], [4], [4], [2] for multiple Solution cells []
], [3], [1], [], [4], [1], [], [], [1], [4], []]
< P> From here I get a "sample", I find the shortest length in the solution list which is not equal to 1, and I try the first possible number of this cell and put me in that fixedlist here There is an algorithm for updating nearby cells and checking whether it is still a compact sudoku If not, then I do not know how to get rid of one and try a new one. I know this pseudo code and I can use it for essential languages, but not for Erlang.
These are common functions that provide structure to handle back-tracking and logical variables similar to the Prol engine. You must provide a program that describes the program logic. If you write them as you are in Prolal, then I can show you how they should translate into Erlang. In a nutshell you translate something like this:
p: - q, r, s
in something
p (next 0) - & gt; Next 1 = Funny () - & gt; S (Next) End, Next 2 = Funny () - & gt; R (next 1) end, Q (next 2).
Here I am ignoring the continuation of all other arguments.
I hope this helps some as I said that if you describe your algorithm, then I can help you translate them, I am looking for a good example. You can, of course, do as well as yourself, but it offers some help.
Comments
Post a Comment