Can anyone point at an algorithm that'll tell me how many solutions there are? - do Angusj's and simes's applications actually work each one out and count as they go?
stuartn
The easiest way is to pop it into one of the programs
I can't speak for Angusj's but that's exactly what mine does - works out each possible solution, and counts as it goes.stuartn wrote:Can anyone point at an algorithm that'll tell me how many solutions there are? - do Angusj's and simes's applications actually work each one out and count as they go?
stuartn wrote:Can anyone point at an algorithm that'll tell me how many solutions there are?
SUB Solve1(Puzzle$)
Solve as much as possible using as many techniques as you know
Case: Solved
Add 1 to count of solutions and return
Case: Impossible condition
Just return
Case: Stuck
Let Temp$ = solution so far
Pick a random cell, say 13, that has some pencilmarks, say 3 and 9.
mid$(Temp$,13,1)="3": Call Solve1(Temp$)
mid$(Temp$,13,1)="9": Call Solve1(Temp$)
return
rubylips wrote:It's fine to use recursive calls if the number of solutions is known to be small (though I'm not sure how you'd know) but you'll almost certainly find it necessary to use an iterative technique to count large numbers of solutions in order to avoid stack overflows.