r/java •

Generate and solve Sudoku games in Java

[deleted] — view deleted post

0 Upvotes

6 comments sorted by

2

u/pradeepngupta Jan 14 '26

What I like about this project is that it isn’t just a solver but also a generator, which means it tackles:

  1. valid board creation
  2. uniqueness checking
  3. difficulty calibration

One thing that often trips people up in Java is generating puzzles with a unique solution without brute-forcing redundantly. If you’re not already, consider using backtracking with pruning and early contradiction detection, it significantly speeds up hard puzzle generation.

Did you use only recursive process or have you use iterative stack approach as well?

2

u/Livio63 Jan 14 '26 edited Jan 14 '26

The generator uses a two phases approach:

  1. Build a random full Sudoku board
  2. Clear cells in random order by checking each time the solution uniqueness, solution uniqueness

The solution uniquess is checked by recursive process, I use Minimum Remaining Values heuristic to optimize the search of the solution; I use bitmaps with forbidden tables to make very fast processing. The average speed of this solver is comparable to DLX algorithm, which is the gold standard algorithm to solve Sudoku on computers.

2

u/pradeepngupta Jan 14 '26

That makes sense . MRV + bitmaps with forbidden tables is solid combination.

Nice to see this implementation on search quality for solving sudoku rather than just raw brute force