Weblog Categories Main Books (3) Bowling (5) Computing Devices (1) Politics (26) Religion (7) Science (2) Stained Glass (1) Sudoku (60) Television (2) Toronto (15) Trains (9) Archives April 2008 (1) March 2008 (7) February 2008 (2) January 2008 (5) December 2007 (4) November 2007 (4) October 2007 (8) June 2007 (2) October 2006 (2) July 2006 (1) May 2006 (3) April 2006 (1) March 2006 (3) February 2006 (1) January 2006 (6) December 2005 (5) November 2005 (5) August 2005 (18) July 2005 (29) June 2005 (13) May 2005 (2) April 2005 (5) March 2005 (8) February 2005 (4) ![]() Sudoku Introduction How to solve Standard Puzzles Advanced Puzzles Nonomino Puzzles Comments Weblog #1 #2 #3 #4 #5 #6 #7 #8 #9 #10 #11 #12 #13 #14 #15 #16 #17 #18 #19 #20 #21 #22 #23 #24 #25 #26 #27 #28 #29 #30 #31 #32 #33 #34 #35 #36 #37 #38 #39 #40 #41 #42 #43 #44 #45 #46 #47 #48 #49 #50 #51 #52 #53 #54 #55 #56 #57 - January Web Stats #58 #59 #60 ![]() Unclassifieds FAQ Guest book Recommended Links |
NoticeI am no longer posting new puzzles to this blog. For all of my Sudoku puzzles, old and new, please visit Sudoku in another section of this website. I will still create and offer new puzzles, in batches of a couple of hundred, once a week or so. Sudoku #34Category: Sudoku Previously, I talked about rewriting my Sudoku program from Python to C to improve its run-time performance. Not content to leave well enough alone, I decided to try to improve performance a bit more by tweaking the algorithm. (The following discussion is probably of interest only to computer programmers. For others, feel free to skip ahead to todays puzzle.) First, let me summarise how I first implemented the basic Sudoku
solving methods. Function The performance enhancement I wanted to try was to just consider the unknown cells within a group, rather than all of them. The idea was that each group would be partitioned into two areas. When a cell gets set a specific value, the cell would be then be moved into the bottom half of the group, and further analysis would then consider just the unknown cells at the top of the group. Unfortunately, the recursion of the three basic functions meant
that cells would get set and unique possibilities searched for
before certain possibilities were eliminated from all of the cells
of a group. Which meant that function The answer was to implement another performance improvement,
changing the recursive algorithm into an iterative one. Function
What kind of improvement did I get from these two changes? My old program could generate about six puzzles per minute. The new one could now produce about 28 puzzles per minute. That's more than a four times improvement! With this one application, I've now demonstrated three ways you can improve performance in your code: First, use a compiled language; second, find a better algorithm; and third, convert a recursive algorithm into an iterative algorithm. And now, on to todays Sudoku puzzle. Hans
path: /Sudoku | permanent link to this entry ![]() | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||