Skip to content

Conversation

@larsbonczek
Copy link

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


// Default unique to true
unique = unique || true;
if(typeof unique === "undefined"){
Copy link
Owner

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*
Copy link
Owner

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){
Copy link
Owner

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 (===)

@robatron
Copy link
Owner

robatron commented Dec 6, 2025

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

This is broken. Every puzzle has 20+ solutions.

2 participants