21
votes
Accepted
Maximize Sudoku King's tour
Python + Z3, 999899898789789787876789658767666545355432471632124566352413452143214125313214321, optimal
Runs in about half an hour, producing
...
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$ # ...
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
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-...
9
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 ...
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
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
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?)
6
votes
Output a Sudoku board
JavaScript (Node.js), 47 bytes
Output as an array of the rows.
_=>[...w="147258369"].map(x=>(w+w).substr(x,9))
Try it online!
Generates this:
472583691
...
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 ...
6
votes
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 ...
5
votes
Accepted
Morse sudo-ku-de
APL (Dyalog Extended), 42 bytesSBCS
Anonymous tacit prefix function.
⌂morse{1↓∊' ',¨⍺⍺∊⍕¨⊃⌂sudoku⍎¨9 9⍴⍺⍺⍵⊆⍨≠⍵}
Try it online!
...
5
votes
5
votes
Solving an easy Sudoku in increasing digit order
JavaScript (ES6), 239 bytes
Returns a string of digits, or undefined if no set at all was completed.
...
4
votes
4
votes
4
votes
4
votes
4
votes
Output a Sudoku board
Batch, 84 bytes
@set s=123456789
@for %%a in (0 3 6 1 4 7 2 5 8)do @call echo %%s:~%%a%%%%s:~,%%a%%
Uses @Mnemonic's output. ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
sudoku × 28code-golf × 21
puzzle-solver × 7
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
open-ended-function × 1