As of May 31, 2023, we have updated our Code of Conduct.

Hot answers tagged

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 ...
jimmy23013's user avatar
  • 36.6k
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 ...
feersum's user avatar
  • 31.1k
21 votes
Accepted

Maximize Sudoku King's tour

Python + Z3, 999899898789789787876789658767666545355432471632124566352413452143214125313214321, optimal Runs in about half an hour, producing ...
Anders Kaseorg's user avatar
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 ...
mbomb007's user avatar
  • 23.2k
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$ # ...
53x15's user avatar
  • 349
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: <...
Neil's user avatar
  • 158k
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!
xnor's user avatar
  • 141k
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 <...
Kevin Cruijssen's user avatar
10 votes

Unique Sudoku Finder

Brachylog, 245 bytes /2 = 122.5 ...
Fatalize's user avatar
  • 37.9k
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... ...
Leaky Nun's user avatar
  • 49.1k
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(\...
Jonathan Allan's user avatar
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-...
BradC's user avatar
  • 6,767
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 ...
Value Ink's user avatar
  • 11.6k
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 ...
Martin Ender's user avatar
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 ...
nutki's user avatar
  • 3,717
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. ...
Conor O'Brien's user avatar
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 ...
Arnauld's user avatar
  • 181k
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 ...
Ton Hospel's user avatar
  • 14.8k
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 ...
Bubbler's user avatar
  • 70.3k
7 votes

Draw a sudoku board using line drawing characters

PHP, 297 bytes ...
Jörg Hülsermann's user avatar
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?)
Erik the Outgolfer's user avatar
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 ...
Mirage's user avatar
  • 71
6 votes

Regex Golf: Verify a Sudoku Solution

Javascript regex, 532 530 481 463 chars Validate rows: ...
Qwertiy's user avatar
  • 2,989
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 ...
TFeld's user avatar
  • 19.8k
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 ...
Nick Kennedy's user avatar
  • 16.8k
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 ...
Christian Sievers's user avatar
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] ...
Angs's user avatar
  • 4,957
5 votes

Draw a sudoku board using line drawing characters

T-SQL, 445 437 bytes (in 381 characters) ...
BradC's user avatar
  • 6,767
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 ...
dylnan's user avatar
  • 5,334

Only top scored, non community-wiki answers of a minimum length are eligible