-
Notifications
You must be signed in to change notification settings - Fork 144
Implement puzzle uniqueness #5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
|
|
||
| // Default unique to true | ||
| unique = unique || true; | ||
| if(typeof unique === "undefined"){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for fixing this!
| By default, the puzzles are unique, uless you set `unique` to false. | ||
| By default, the puzzles are unique, unless you set `unique` to false. | ||
| (Note: Puzzle uniqueness is not yet implemented, so puzzles are *not* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This note can be deleted now since you've implemented this functionality 😄
| // Check if "backwards" solution is equal to regular solution. | ||
| // If it is, the sudoku has a unique solution. | ||
| const reverseSolution = sudoku.solve(board, true); | ||
| if(reverseSolution == solution){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should use strict comparison here (===)
|
Hey, thanks for the PR, @larsbonczek! Love the bi-directional solving approach; clever use of existing functionality 👍 Left a few comments, but overall I think this is a pretty reasonable implementation! Let me know if you want to update those or if you'd like me to push the changes to your branch. |
Implements puzzle uniqueness by checking whether the solution obtained by rotating through the possibilities in reverse matches the regular solution. If it does, only this one solution exists.
There is probably a better way to do this, but it seems to work.
Fixes #3