this post was submitted on 05 Sep 2024
15 points (100.0% liked)
Programming
17392 readers
153 users here now
Welcome to the main community in programming.dev! Feel free to post anything relating to programming here!
Cross posting is strongly encouraged in the instance. If you feel your post or another person's post makes sense in another community cross post into it.
Hope you enjoy the instance!
Rules
Rules
- Follow the programming.dev instance rules
- Keep content related to programming in some way
- If you're posting long videos try to add in some form of tldr for those who don't want to watch videos
Wormhole
Follow the wormhole through a path of communities [email protected]
founded 1 year ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
view the rest of the comments
Hmm, I could have sworn I had code for this but I'm not able to find it. I wrote a DLX impl many years ago and used it for a few things, and I wrote several different sudoku solvers, but I don't seem to have ever used my DLX impl to solve sudoku puzzles...
What you need to do is create a row for every possible entry and location in the puzzle. So you will have a row representing every single possible entry option. 9 options x 81 total squares = 729 total rows.
The columns in your Exact Cover Matrix represent all the different constraints, where each column must be unique in the solution.
So your Exact Cover Matrix will need 324 columns = 81 (squares) + (9 (numbers) * 9 (rows)) + (9 (numbers) * 9 (cols)) + (9 (numbers) * 9 (boxes))
When you fill out all the rows, you'll place 1's in all the columns that that specific entry aligns with. Take the example of the row corresponding to the entry "5" in the Sudoku Puzzles top left box. That row in your Exact Cover Matrix will contain:
To feed a specific puzzle into your solver, it kinda depends on the solver, you just need to force the output to contain those specific rows.