N Queens?
I was trying to solve the Standard N Queens problem and came up with this Code, it's in Python maybe I'll do this is C++ too, but really with that cryptic syntax of vectors, it looks really tougher to understand code compared to the ones written in Python although there isn't much difference that would arise if we remove those vector syntax. Well, I am working on 1 more problem that I have been trying to solve for the last 3 days, and today came with one idea that passed all the sample Test Cases but the irony is that when it came to other Test Cases, it failed badly and now I can't figure out what bug is there in my code, cause it's a fairly long code and also there is not surety of whether the logic that I am using is correct or not.
For the below syntax I think that the code should be sufficient and also not to mention that this problem is very much related to the DFS traversing technique of Graphs where it was Vertices that we were traversing through but here we have Chess Board Positions, the idea is same, here also the function calls are being used a built in stack. And after every conclusion that is not final we move on to the next option by backtracking to the previous choices and continue with the options untill we run out of choices and eventually return False as the result. For no result also I am printing the Board.
And I have kept print statements to describe and give a better understanding of the state of the Program and how the backtracking is working, you just have to imagine the Chess Board( just a 2D Matrix ) and you will get the Problem.
Comments
Post a Comment