Skip to main content
    Country/region select      Terms of use
     Home      Products      Services & solutions      Support & downloads      My account     

developerWorks  >  Lotus  >  Forums & community  >  Best Practice Makes Perfect

Best Practice Makes Perfect

A collaboration with Domino developers about how to do it and how to get it right in Domino

When I saw Heinz Ulrich Krause's version of a Sudoku puzzle in Notes, I just had to write a tool to save time for busy Notes developers and end users by solving the puzzle for them. Unfortunately, Heinz' solution doesn't allow for a parasitic agent to solve the problem automatically by sending instructions to the NotesUIDocument. His code to recalculate the possible values for remaining empty cells only executes in the context of prompting the user to select a value, something we can't easily do through UI commands. So I created a version that's probably very similar to the one by Rudi Knegt which Heinz doesn't like, with redundant formulas, so that I could plug in a value and refresh the form to get the new sets of remaining choices for empty cells. I'm sure it's not as fast as Heinz' version, but you don't have to solve the puzzle manually, so from a productivity standpoint this is a winner. Also, as I note in my response to his post, his has a bug.

I'm sure the code could be made faster, but it's fast enough for manual solving. Also, it's kind of fun to watch the auto-solver trying different combinations. It might be harder to make out what's going on, if the form were much more efficient.

To use the application, which is attached, open it, open one of the puzzles provided for you (or use menu Create / Sudoku to start with a blank grid, enter a puzzle from elsewhere, and save). Then, use menu Actions / Solve it to zip through the combinations until a solution is found. The solver isn't very intelligent -- it looks at the list of choices for each cell and finds the cell with the fewest choices. It chooses a value from this shortest list, and puts the cell information on a stack. In case it turns out that was the wrong choice, it can undo the change and try the next value. When it runs into a dead end (a cell for which no valid choices remain) it backs up the stack, erasing values, until it gets to one with a possible value it hasn't tried yet.

As you watch the solver run, you may occasionally see "###" flash up in a cell. That's the signal that it has run into a dead end and is backtracking to the last point where it had a choice, to try a different value. When adding values, we always refresh after each change, but when erasing, we can tell from the information in our stack how many cells to delete and what is the next value to try, so a refresh at each step is not required.

Andre Guirard | 16 March 2008 11:37:46 PM ET | Home, Plymouth, MN, USA | Comments (2)


1) The Sudoku solver
Ulrich Krause | 3/17/2008 2:31:44 AM

Great! Thank you, Andre.

2) The Sudoku solver
Rudi Knegt | 4/28/2008 4:39:30 PM

I have to check this one out, but I have to say that mine was build for the UI, and way back in R6 days, If I remember correctly back in 2003 or so, but the database has been redone so much that I can't be sure there.. so let's see if I can finally automate my version as well, and we can "compete" a little bit. :-)


 Add a Comment
Comment:  (No HTML - Links will be converted if prefixed http://)
Remember Me?     Cancel

Search this blog 


    About IBM Privacy Contact