Skip to content

Conversation

@Visali-AL
Copy link

@Visali-AL Visali-AL commented Nov 23, 2025

Hello! @norvig

Truly humbled by this collection of yours! Thank you for taking all the time to build this repo!

I've added 2 fixes to make the isSolution method work as expected + An enhancement to identify the exact puzzle number as is from the input file

The problem was that although the puzzles did get solved, the program still output that it had failed.

  1. The units' positions were summed to match the ALL_DIGITS permutation. Modified it to make the values of the positions sum up to the ALL_DIGITS permutation (Due to this, though the program did find the solution, the answer informed that it failed)

Before

if (IntStream.of(u).sum() != ALL_DIGITS) return false;

Screenshot 2025-11-23 at 3 16 49 PM

After

if (Arrays.stream(u).map(sq -> grid[sq]).sum() != ALL_DIGITS) return false;
Screenshot 2025-11-23 at 3 21 06 PM

  1. If the puzzle wasn't solved within Constraint Propagation and had to move to search, although the search did return the right result, pass by reference was let to point us back to the latest solution, and when this didn't happen, an inconsistent state of solution was taken for validation, making the program prompt a failure again.

Before

if (runSearch) search(solution, gridpool, 0); // on these 2 lines.

Screenshot 2025-11-23 at 3 25 16 PM

After

Honouring the result from the search always, fixed this!
if (runSearch) solution = search(solution, gridpool, 0);
Screenshot 2025-11-23 at 4 05 18 PM

  1. Lastly, when solving the puzzles in multi-threaded fashion, the puzzle number wasn't matching the exact number from the input file. i.e, Puzzle # 1234 of Thread-1's grid list, and then again it was puzzle # 1234 of Thread-2's grid list etc., Modified the code to print the exact puzzle number from the input file. (To make it easier to get the input string for the exact puzzle that failed from the .txt file)
Screenshot 2025-11-23 at 3 38 24 PM Screenshot 2025-11-23 at 3 39 11 PM

Please do feel free to let me know if you have any comments! Thank you!

@Visali-AL Visali-AL changed the title Code fix in validating solution + An enhancement to identify the puzzle number Code fix in validating Sudoku solution + An enhancement to identify the exact puzzle number Nov 23, 2025
@Visali-AL Visali-AL changed the title Code fix in validating Sudoku solution + An enhancement to identify the exact puzzle number Code fix in Sudoku solution validation + An enhancement to identify the exact puzzle number Nov 23, 2025
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.

1 participant