42
votes
Accepted
Regex Golf: Verify a Sudoku Solution
Ruby regex, 71 78 73 bytes
^(?!.*(?=(.))(.{9}+|(.(?!.{9}*$))+|(?>.(?!.{3}*$)|(.(?!.{27}*$)){7})+)\1)
I don't really know Ruby but apparently it doesn't complain ...
33
votes
Regex Golf: Verify a Sudoku Solution
PCRE, 117 119 130 133 147 bytes
^(?!(.{27})*(...){0,2}(.{9})?.?.?(.).?.?(?=(?2)*$).{6,8}(?3)?\4.{0,17}(?1)*$|.*(.)(.{8}(?3)*|((?!(?3)*$)(|.(?7))))\5)
Should also ...
21
votes
Accepted
Maximize Sudoku King's tour
Python + Z3, 999899898789789787876789658767666545355432471632124566352413452143214125313214321, optimal
Runs in about half an hour, producing
...
15
votes
Regex Golf: Verify a Sudoku Solution
.NET regex, 8339 bytes
Yes, I know my solution is very naive, since Martin told me he did it in like 130 bytes. In fact, the URL to try it online is so long that I couldn't find a URL shortener that ...
15
votes
Accepted
The fastest Sudoku solver
C++ - 0.201s official score
Using Tdoku (code; design; benchmarks) gives these results:
~/tdoku$ lscpu | grep Model.name
Model name: Intel(R) Core(TM) i7-4930K CPU @ 3.40GHz
~/tdoku$ # ...
14
votes
Regex Golf: Verify a Sudoku Solution
.NET regex, 121 bytes
^(?!(.{27})*(.{9})?(...){0,2}.?.?(.).?.?(?=(...)*$)(.{9})?.{6,8}\4.{0,17}(.{27})*$|.*(?=(.))((.{9})+|(.(?!(.{9})*$))+)\8)
Explanation:
<...
12
votes
Output a Sudoku board
Python 2, 47 bytes
l=range(1,10)
for x in l:print(l*9)[x*8/3:][:9]
Try it online!
11
votes
Validate Sudoku on a Mobius Strip
05AB1E, 54 47 bytes
3δôø˜©‚˜9ôI2ä`í«ø«D€ÙQIÂí‚øε˜Ć}D€ÔQ®9ô€Ås9L¢<PP
Takes the input as a 6x27 matrix, kinda like the reference screenshot of the grid.
Outputs <...
10
votes
10
votes
Draw a sudoku board using line drawing characters
Python 3, 232 bytes
Thanks to those who helped to golf this down.
Encryption within encryption...
...
10
votes
Counting valid Binary Sudoku rows
Jelly, 13 12 9 bytes
ŻcṚ$+Ḋ$²S
Try it online! Or see the test-suite.
How?
This code is calculating
$$\sum_{k=\lceil\frac{n}{2}\rceil}^{n}\big(\...
9
votes
Output a Sudoku board
T-SQL, 96 89 bytes
Found one shorter than the trivial output!
SELECT SUBSTRING('12345678912345678',0+value,9)FROM STRING_SPLIT('1,4,7,2,5,8,3,6,9',',')
Extracts 9-...
8
votes
Regex Golf: Verify a Sudoku Solution
PCRE, 3579 bytes
An absolutely terrible brute force solution. Negative lookbehinds ahoy!
I spent way too much time on this to abandon it, so here it is, for posterity's sake.
On the bright side, if ...
8
votes
Regex Golf: Verify a Sudoku Solution
Ruby flavour, 75 74 bytes
Thanks to jimmy23013 for saving 1 byte.
^(?!(.{9}*(.|(.)){,8}|.*(\g<2>.{8})*|.{27}?.{3}?(\g<2>{3}.{6}){,2}.?.?)\3).
Test ...
8
votes
Build a minimum-clue Sudoku unsolver
C - 2,361,024 2,509,949 clues
Remove clues starting from the last cell if a brute force solver finds only one unique solution.
Second try: use heuristic to decide in which order to remove clues ...
8
votes
Draw a sudoku board using line drawing characters
C (gcc), 398 395 291 bytes
Saved 3 bytes by working through the string reversed, and 104 (!) bytes thanks to Leaky Nun.
...
8
votes
The fastest Sudoku solver
Node.js, 8.231s 6.735s official score
Takes the file name as argument. The input file may already contain the solutions in the format described in the challenge, in which case the program will ...
7
votes
Implement a Brute Force Sudoku Solver
Perl, 120 bytes
Oh, I remember golfing that back in 2008...
And it in fact stopped working in perl 5.12 since implicit setting of @_ by split was removed then. So only try this on a sufficiently old ...
7
votes
Create a diagonal sudoku board
APL (Dyalog Unicode), 56 bytes
(,⊖⍣(?2)↑a(3+⍳3)(10-⌽a←3?3)){⍺ ⍺⌷9 9⍴∊⌽⍵∘.⌽⍵⊖¨⊂3 3⍴⍳9}⍳3
Try it online!
A full program that randomly gives a 9-by-9 matrix of ...
7
votes
7
votes
Output a Sudoku board
Jelly, 7 bytes
9Rṙ%3$Þ
Try it online!
And a little bit of this...
-1 thanks to Jonathan Allan('s thinking?)
7
votes
The fastest Sudoku solver
C - 0.045s unofficial score
I got this time on my i7-9750H with 6 cores 12 threads @ 4Ghz. I'm aware that my cpu is faster than the i7-7700HQ so I think (hope) it would be closer to 0.080s if it were ...
6
votes
Regex Golf: Verify a Sudoku Solution
Javascript regex, 532 530 481 463 chars
Validate rows:
...
6
votes
Output a Sudoku board
Python 2, 53 bytes
r=range(9)
for i in r:print[1+(j*10/3+i)%9for j in r]
Try it online!
Alternatives:
Python 2, 53 bytes
...
6
votes
Is this board Latin-style?
Jelly, 24 bytes
,ZµŒgaS$€F)Zṣ€0Ṣ<JƊ€€)FẸ
Try it online!
A monadic link taking as its argument the grid as a matrix with 1 representing squares needing a ...
6
votes
Counting valid Binary Sudoku rows
Pari/GP, 77 bytes
n->polcoeff([x,0,1,0]*[0,x,1,0;0,0,1,0;x,0,0,1;x,0,0,0]^(2*n-1)*[1,1,1,1]~,n)
Try it online!
This uses a nice method involving automata and ...
5
votes
Find the rows which make each column have one True (was: Knuth's Algorithm X)
Haskell, 100 93 92 87 83 80 bytes
Knuth's algorithm:
g&c=filter(g.any(`elem`c))
(u:v)%a=[c:s|c<-id&u$a,s<-(not&c)v%(not&c$a)]
x%_=[x]
...
5
votes
Draw a sudoku board using line drawing characters
T-SQL, 445 437 bytes (in 381 characters)
...
5
votes
Output a Sudoku board
Python 3, 58 55 bytes
l=*range(10),
for i in b" ":print(l[i:]+l[1:i])
Try it online!
-3 bytes thanks to Jo King,
The ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
sudoku × 27code-golf × 20
puzzle-solver × 6
code-challenge × 5
decision-problem × 5
game × 5
grid × 4
random × 2
binary × 2
fastest-code × 2
algorithm × 2
array × 2
number × 1
ascii-art × 1
sequence × 1
kolmogorov-complexity × 1
matrix × 1
optimization × 1
regular-expression × 1
compression × 1
conversion × 1
board-game × 1
binary-matrix × 1
test-battery × 1
morse × 1