Simple algorithm for a sudoku solver java -
i've been stuck on thing while, can't wrap head around it. homework, have produce algorithm sudoku solver can check number goes in blank square in row, in column , in block. it's regular 9x9 sudoku , i'm assuming grid printed have produce part solves it.
i've read ton of stuff on subject stuck expressing it.
i want solver following:
- if value smaller 9, increase 1
- if value 9, set 0 , go 1
- if value invalid, increase 1
i've read backtracking , such i'm in stage of class i'd keep simple possible.
i'm more capable of writing in pseudo code not algorithm , it's algorithm needed exercise.
thanks in advance guys.
seeing it's homework, believe can point in general direction.
to start, keep two-dimensional array (or data structure can represent grid), , keep track of values can go there. let's it's class named "possibilities":
public class possibilities { //keep track of numbers possible internally, accessor }
the way sudoku works, there square single answer (in cases, won't available, means need potentially make copy of data , play out little bit, or have way roll back). put, fill in answer, , iterate on adjacent squares remove freshly put number possibility (and check squares simultaneously new potential answers).
Comments
Post a Comment