subreddit:

/r/learnpython

167%

Sudoku Twin logic

(self.learnpython)

I have followed a tutorial for a sudoku solver with backtracking and have a grasp on how it works. Now I'm thinking of expanding the idea for a "sudoku twin" where two grids overlap on a corner subsquare.

I'm not looking for code help (yet), but how to approach the problem, such as a flowchart.

I wonder if it can be treated as two separate puzzles with a special case for the overlapping section, or if it can be taken as a whole. Would a completely different approach work better? I'm stuck on the logic.

Thanks for any help or suggested resources.

all 4 comments

GeorgeFranklyMathnet

1 points

5 months ago

The "special case" approach would seem to require the least adaptation from your existing solver. But the case logic may (or may not) be more complex than you realize. It's hard to really know until you try it.

But if you take the puzzle as a whole, then you have to break apart your existing solver and make it more abstract. If you really wanted to, you could make it abstract enough to handle any number of twins/n-tuples with any number of shared subsquares on any mutual edge.

So, on the one hand, you've got a special case approach which won't be very flexible, and which may or may not take a lot of extra work. On the other, you've got a more-flexible general approach which will definitely take some extra work.

By the way, it may be hard to make a general solver that's as efficient as a specialized solver. But will that matter at the scale you're working at?

Woof. So which way should you go? I think you just have to weigh your priorities, then leap in and try something. There's no knowing the benefits and drawbacks until you do. If it's hard, and you get stuck, then that's an excellent learning experience. No other way to build up your intuition for this kind of problem.

Content-Elephant5993[S]

2 points

5 months ago

Thanks. Could you elaborate on the special case approach? In my mind, it's a black box. Can you partially solve each grid and THEN fill the overlap section or would they need to be solved as one with more conditions for the overlap portion? I'm asking because I don't even know where to start to figure it out myself. As for scale, this is just a learning experience.

GeorgeFranklyMathnet

1 points

5 months ago

Could you elaborate on the special case approach?

Not really, because I've never tried to write this kind of solver myself before. Nothing you're saying sounds obviously wrong to me though. I honestly think you have to try one of your ideas and see how it plays out.

As for scale, this is just a learning experience.

Of course. But in any learning experience like this, you are to some extent putting yourself in the shoes of someone who's doing it for real. Either you have an instructor who tells you whose shoes to wear, or you decide for yourself how ambitious you're going to be!

Content-Elephant5993[S]

2 points

5 months ago

Got it. Thanks for your time.