Sudoku Challenge
Solve the given sudoku.Input
One sudoku puzzle. Squares are given in left-to-right, top-to-bottom order. A digit stands for itself, whereas a period indicates a square that is to be filled. You should not assume anything about other characters, i.e., they should be ignored. The input is guaranteed to have exactly one solution.Output
The solution to the given sudoku (with all squares filled). Nine lines, each containing one row of the solved sudoku.Sample Input 1
1.45..89. .963..5.1 53.41.... 6......25 2.9...3.7 48......6 ....37.54 9.7..563. .45..12.9
Sample Output 1
124576893 796328541 538419762 671893425 259164387 483752916 862937154 917245638 345681279
Sample Input 2
9...28.575...192.3.3.5...6..8.2..395...7.6...341..5.2..6...7.3.1.895...475.46...9
Sample Output 2
916328457 574619283 832574961 687241395 295736148 341895726 469187532 128953674 753462819
All Submissions
Best Solutions
Point Value: 12 (partial)
Time Limit: 2.00s
Memory Limit: 256M
Added: Jul 07, 2009
Author: bbi5291
Languages Allowed:
C++03, PAS, C, HASK, ASM, RUBY, PYTH2, JAVA, PHP, SCM, CAML, PERL, C#, C++11, PYTH3
Comments (Search)
I thought that was brute force, but was probably mistaken.
It ended up being the fastest solution so far... (Probably just because of bit operations)
What would my solution be classified as, and is Knuth's way theoretically faster? (I can't tell what it does by looking)
BTW, according to a couple of sudoku websites, multiple-solution sudokus are considered invalid...
The example cases were among the easiest I could find.
I'm reducing the value.
I would assume the same applies to this.
In Ruby, primes takes 3 ms on my computer. It takes eight times that amount here.
My C++ solution passes every case in no more than 12 ms. Unless Ruby is hundreds of times slower than C++ (honestly, I see no reason why it should be more than 10-20 times slower, and you just pointed out that Primes was 8 times slower), the choice of algorithm should be more important here than the choice of language.
However, using Ruby 1.9 sped this up to about 8 seconds. When I try to use it in the judge I get SIGABRT, though...