Solving the N Queens problem using Dart.
You can refer https://www.geeksforgeeks.org/n-queen-problem-backtracking-3/ for information about the problem and other solutions.
Also, shout out to my friend, SamLikesCoding for giving this problem a go. Here's his code in case you wanna check it out.
Contains a class NQueens which has 2 fields.
- n => Board Size
- board => Solution List where index correspond to row and value corresponds to column
Methods:
- _canPlace(int x, int y) This method checks whether a queen can be placed at (x,y) of the board
- solve() Updates board with the solution.
- printBoard() Prints the solution board with 1 as Queen and 0 for Empty.
- isSolved() Checks if the board has been solved. If false is returned after Nqueens.solve(), no solution exists.