Humm... my code seems to have distorded a bit, it used to take "only" 200 ms on this one, now it takes about 400 ms. Have to check it after I've slept. This code is so slow for me due to one reason: it effectively acts as the "worst case scenario" for the backtracking code I use to solve the ones the pure logic code can't handle.
Edit Duh, silly of me! Should remember NOT to run benchmarking in power saving mode Now gives me 190 ms.
That's interesting...quite a result. My initial result for that is 155,6ms so achieving time under 1ms seems very good. I'm not on my primary PC right now and I got that result with a P4 1.7 Ghz. Out of curiosity, what's the configuration you used to get the result (processor, VB6/VB.Net, Debug/Release, IDE/Commandline)?
I understand that the total time it takes to solve a number of sodukus will be the actual winning factor since I guess that most people's algorithms will solve all sodukus. I'm just wondering here...but if the benchmarking box is hyperthreaded wouldn't a threading solution perform better than a single-threaded one for lots of sodukus?
I still don't see the timing class to be used for VB.Net solutions.
That's interesting...quite a result. My initial result for that is 155,6ms so achieving time under 1ms seems very good. I'm not on my primary PC right now and I got that result with a P4 1.7 Ghz. Out of curiosity, what's the configuration you used to get the result (processor, VB6/VB.Net, Debug/Release, IDE/Commandline)?
It solved it using LOGIC only... maybe your missing some rules in your program...
My configuration: P4, 1.4 GHz, VB6, Compiled with ALL optimizations, And by all optimizations, I mean this:
Well, I'm not up to building msk files like Merris last one yet, although given a day or two {where My car doesn't break down, go into shop, or I'm sitting around waiting for the phone to ring telling me that its fixed, while I'm busy trying to shuttle back and forth between work & home to care for my bedridden mom} I could incorporate that. Propably next weekend.
But I tweaked my generator a little bit more. Theoretically, if you know the proper strategies, you can, so far, solve any of mine without any brute force.
So, attached are a few more patterns for you to play with. Please inform me if I've screwed up and made invalid patterns.
It solved it using LOGIC only... maybe your missing some rules in your program...
Yeah, you're right. A small adjustment brought it down to 10ms...although I don't think I'll see anything close to 1ms. I'm using VB.Net and a class-based solution (no plain arrays or structures) so that's going to incur some performance penalty.
I've fooled around a bit and I think that the benchmarking box could make a difference after all. For the patterns posted by Pino, threading isn't worth the trouble because the respective solutions are calculated very fast on a single thread. The patterns posted by NotLKH are a different story - a hastily written threading solution is 15% faster than a single threaded one using the same algorithm (with hyperthreading processor - if you force the process affinity for one CPU only, the performance gain drops below 2%).
For the patterns posted by Pino, threading isn't worth the trouble because the respective solutions are calculated very fast on a single thread. The patterns posted by NotLKH are a different story - a hastily written threading solution is 15% faster than a single threaded one using the same algorithm ...
I'm not sure, but I think Pino's are NotLKH's first round of patterns, and what you are referring to as NotLKH's are his second round of patterns.
If so, it sounds like NotLKH is evolving along pretty good?
Some of NotLKH's sudokus are too easy In the other hand it is good to test the easy ones too, that is one of the things that make the difference when the final tests are done.
Hardest for my solver in NotLKH's newest set:
147,824374 ms: 023_0807_XXXX__SOD_MASKED.msk
(or 0,147823 seconds)
Total time to solve all 532 sudokus: 1,695153 seconds
If so, can I see the code you use for timing to .000023 seconds {23 thousandths of a millisecond, oops, forgot the furthur 187 points of accuracy beyond thousandths of a thousandth}, merri?
-Lou
Last edited by Something Else; Aug 1st, 2005 at 08:45 PM.
0.091 sec. with 2.6GHz for that 532-set.
But it's in C, I don't know about VB, is it much slower than C ?
Another suggestion : transform the puzzles randomly by one of the
9!*6^8*2 equivalence transformations, since many solvers heavily depend
on the order of rows,columns in which the puzzle is processed.
The nature of the language is different, but I don't believe there is much diffence in this task: VB6 compiler is a hacked C compiler. My "poor" result is due to the fact the harder ones require backtracking, as I haven't yet bothered to code a good logical solver. Some easier ones are solved lightning fast thanks to the optimized basic logic.
The nature of the language is different, but I don't believe there is much diffence in this task: VB6 compiler is a hacked C compiler. My "poor" result is due to the fact the harder ones require backtracking, as I haven't yet bothered to code a good logical solver. Some easier ones are solved lightning fast thanks to the optimized basic logic.
then I don't understand why you wrote earlier that you can't easily adapt
it for larger sudokus like 16*16 etc. ?
My solver is just an exact-cover solver, so I needn't bother about
all these "sudoku-rules".
Because it is highly optimized already: I use fixed size arrays and precalculated values. Also, VB is slow with multidimensional arrays, so I use one dimensional array. If the contest required different sized sudokus, then I'd code it flexible. But that'd require changing quite many values and doing some light extra math and so on.
I use fixed sized arrays, single dimensional array, and precalculated values, and all the "tricks" i can think of to make it fast, but I still can't get to work at the speeds Merri posted.... the fastest I got was like 0.3 milliseconds (that's 0.0003 seconds), but his speeds I see like 0.02 milliseconds... how the hell is that possible
Can't tell or we'll all post the same code I don't even dare to post a tip, because any tip I could give would be an instant "AHA! GOTCHA!"... this is a contest after all
Well, I'm not up to building msk files like Merris last one yet, although given a day or two {where My car doesn't break down, go into shop, or I'm sitting around waiting for the phone to ring telling me that its fixed, while I'm busy trying to shuttle back and forth between work & home to care for my bedridden mom} I could incorporate that. Propably next weekend.
But I tweaked my generator a little bit more. Theoretically, if you know the proper strategies, you can, so far, solve any of mine without any brute force.
So, attached are a few more patterns for you to play with. Please inform me if I've screwed up and made invalid patterns.
-Lou
I have just been introcuced to Sudoku, wrote a simple solver in tcl/tk on a Mac powerbook. All the puzzles presented by Lou are VERY easy. The hardest puzzles I have seen sofar (and my solver can solve them all) are those given at
Here are the hardest attached in the file format we are using in the contest. It takes four seconds for my solver to complete all 337. However, there are only six which take more than 100 ms (one takes even over 300 ms). There are a few which are very easy as well (ie. didn't require backtracking).
Guess I should start coding more logic to my code, only three weeks to go. Have done some reading and it looks like there is no good single logic that could be used.
I'm not sure about the rules, it seems that you needn't solve all puzzles.
So maybe it's sufficient and a good strategy to specialize on the
easy ones, which are the vast majority, statistically.
Hehe, I guess he is meaning that we would be solving every possible sudoku there is
Anyways, now I'll be getting into the real thing I'm posting for: the contest rules need clarifying. It seems to be unclear what will be timed. Thus some requests:
- It seems that we must clear an array, load a file and solve the sudoku and that this will be timed.
- It would make much more sense if only solving the sudoku would be timed (what if harddisk happened to get busy while loading a sudoku, causing a major slow down to one or more of the contestants?).
- I'm not clearing an array, because when I load a file, I just fill the array according to the file contents (ie. no point clearing it, just slowing down).
- There is no output format defined! My primary suggestion is a Long Array defined to have 81 items (0 To 80) with values from 1 to 9. A secondary suggestion would be a byte array, like SudokuBoard(1 To 9, 1 To 9) where first dimension is Y and second dimension X.
- I also suggest this array to be used as the input array to the solver function. The file loader would then fill the array.
- It seems that we must clear an array, load a file and solve the sudoku and that this will be timed.
Clearing the array is just an assumption I made that you would have to based on my solver I had made (the way it worked, far from optimized). It's not needed to clear/redim the array, you can load the file in a sub and fix the array in there.
Originally Posted by Merri
- It would make much more sense if only solving the sudoku would be timed (what if harddisk happened to get busy while loading a sudoku, causing a major slow down to one or more of the contestants?).
I should have clarified, that's what I was planning to do... Only the solving sub will be timed, not the loading or displaying part.
Originally Posted by Merri
- There is no output format defined! My primary suggestion is a Long Array defined to have 81 items (0 To 80) with values from 1 to 9. A secondary suggestion would be a byte array, like SudokuBoard(1 To 9, 1 To 9) where first dimension is Y and second dimension X.
Use whatever you like, as long as you have a sub that shows the results so we can visually see the solved sudoku somehow (your choise).
Has someone helped you? Then you can Rate their helpful post.
as I understand the rules, contestants will be given a set of sudokus,
maybe similar to the posted one (?), and they will have to solve
them within some time-limit.
When time has elapsed, the correctly solved puzzles are counted.
When the solver finishes before the time has elapsed, then
this time counts in case of a tie.
The codes will be submitted to a tester, who then uses a range of sudokus (not known by the contestants beforehand) which he tests for each code. The winner is primarily determined by the number of solved sudokus, if there is a tie then by speed.
so, would it make sense, if your solver rejects the hard ones or not ?
I mean, you can't know in advance whether you will have enough time
to finish all puzzles , can you ?
So pick the easy ones, while putting the hard ones on some stack,
only to be considered again once you still have time after
finishing the easy ones, etc.
The tester will get lets say 50 sudokus. Then he will test thouse 50 with one contestant, he gets how many was solved, and the total time. Then he tests the SAME 50 sudokus on the next contestant, he writes down how many was solved, and the speed, and so on...
The winner will be that has the MOST Sudokus solved, if there's a tie (i.e. someone has the same number of sudokus solved as someone else) then the winner is the one that has the fastest time.
I'm telling you now, that my solver will solve ALL the sudokus, how fast it will solve, that's another story... I'm sure it won't be faster than Merri's solver, and I'm sure that Merri's solver will solve ALL the sudokus also...
So if you decide so "pick" the ones that you want to solve, then you will lose the contest FOR SURE.
Ok. Here's some more new ones.
Again, if any of you find I screwed up, by finding more than one solution, please tell me so I can address this porblem.
No real big changes to my old code, but it can now solve the hardest set in about 2780 ms. NotLKH's newest set solved in about 260 ms. I've a yet-another-code in the works which is supposed to be able to solve all by pure logic... however, I'm not sure if the logic I've thought for it is valid. I also don't know if I have the time to complete it before the contest deadline, because I started up a new site a week ago and it is still under construction, yet have become the most popular site I administrate.