Permalink
Browse files

Fix bug in elimination counting, thanks to Ahmed Omar for picking it up!

http://erlang.org/pipermail/erlang-questions/2011-March/057193.html

Elimination counts are now:
Solved 50 of 50 puzzles from easy50.txt in 1.286811 secs (38.86 Hz)
  (32833 total eliminations, avg 656.66, median 648, max 808, min 648).
Solved 95 of 95 puzzles from top95.txt in 8.572484 secs (11.08 Hz)
  (210794 total eliminations, avg 2218.88, median 1536, max 10664, min 648).
Solved 11 of 11 puzzles from hardest.txt in 0.391032 secs (28.13 Hz)
  (9516 total eliminations, avg 865.09, median 813, max 1227, min 648).
  • Loading branch information...
1 parent 81b39f2 commit 9125147621faeb11cd46cea5100b2e1e88ff9732 @apauley committed Mar 28, 2011
Showing with 2 additions and 3 deletions.
  1. +2 −3 sudoku.erl
View
@@ -89,9 +89,8 @@ eliminate({false, Count}, _, _) ->
{false, Count};
eliminate(Puzzle, [], _) ->
Puzzle;
-eliminate({Dict, Count}, [Square|T], Digit) ->
+eliminate(Puzzle, [Square|T], Digit) ->
%% Eliminate the specified Digit from all specified Squares.
- Puzzle = {Dict, Count+1},
OldValues = values(Puzzle, Square),
NewValues = exclude_from(OldValues, Digit),
NewPuzzle = eliminate(Puzzle, Square, Digit, NewValues, OldValues),
@@ -105,7 +104,7 @@ eliminate(Puzzle, _, _, Vs, Vs) ->
Puzzle;
eliminate({ValuesDict, Eliminations}, Square, Digit, NewValues, _) ->
NewDict = dict:store(Square, NewValues, ValuesDict),
- NewPuzzle = peer_eliminate({NewDict, Eliminations}, Square, NewValues),
+ NewPuzzle = peer_eliminate({NewDict, Eliminations+1}, Square, NewValues),
%% Digit have been eliminated from this Square.
%% Now see if the elimination has created a unique place for a digit

0 comments on commit 9125147

Please sign in to comment.