Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Challenges

Create a Sudoku

+5
−0

Write the shortest program that takes no input and outputs a Sudoku solution.

For reference, a Sudoku solution is a 9x9 grid of digits where each column, each row and each of the nine 3x3 grids that compose the board have all of the digits from 1 to 9.

Your output may look like this:

123456789
456789123
789123456
231564897
564897231
897231564
312645978
645978312
978312645

Or it may look like this:

123456789456789123789123456231564897564897231564897231897231564312645978645978312978312645

It may be an array of 9 digit integers, 3 digit integers, a 9x9 matrix or nine 3x3 matrices as well.

You may use the digits 012345678, not 123456789, so long as adding 1 to each digit in the output gives a valid Sudoku solution.

There used to be a script to check solutions but it doesn't work. If you code one be sure to tell me.

Your program can have multiple outputs but you'll need to prove that they are all valid solutions.

Have fun, codidactyls!

History
Why does this post require attention from curators or moderators?
You might want to add some details to your flag.
Why should this post be closed?

2 comment threads

0-index? (5 comments)
Your check script fails on some boards (1 comment)

4 answers

You are accessing this answer with a direct link, so it's being shown above all other answers regardless of its score. You can return to the normal view.

+1
−0

APL (Dyalog Unicode), 22 bytes

⎕←∘.((1+⍳9)⌽⍨⊣+3×⊢)⍨⍳3

Try it online!

Requires zero-indexing.

⎕←∘.((1+⍳9)⌽⍨⊣+3×⊢)⍨⍳3
                     ⍳3 ⍝ Make the range [0, 2] (row and cols of 3×3 boxes)
  ∘.                ⍨  ⍝ Outer product with itself
             ⊣+        ⍝ Add the row to
               3×⊢     ⍝ 3 times the column
           ⌽           ⍝ And rotate
     (1+⍳9)             ⍝ The range [1,9] by that much
⎕←                     ⍝ Print that
History
Why does this post require attention from curators or moderators?
You might want to add some details to your flag.

0 comment threads

+3
−0

Haskell, 50 bytes

[take 9$drop i$cycle[1..9]|i<-[0,3,6,1,4,7,2,5,8]]

Try it online!

History
Why does this post require attention from curators or moderators?
You might want to add some details to your flag.

1 comment thread

[46 bytes](https://tio.run/##y0gszk7NyfmfZhvzP7okMTtVwVIlpSi/QKMoNTElOjNWUyVRWzuxJtNGNzGWK9FWydDE3MjU... (1 comment)
+2
−0

BQN, 11 9 bytesSBCS

Run online!

1⌽⍟⊢⍋3|↕9

The result is a length 9 list of lists using the numbers 0 to 8.

The solution is based on the 3x3 transpose list 036147258, obtained with Grade Up. This list is used to repeat the operation rotating itself by one. Since it's a self-inverse, each subsequent rotation starts it at a number one higher than the previous.

1⌽⍟⊢⍋3|↕9
       ↕9  # Range 0…8
     3|    # Mod 3: 012012012
    ⍋      # Grade: 036147258
1⌽         # Rotate by 1
  ⍟⊢       # Repeated n times for each number n

Previous solution (11): Run online!

Idea is to use the numbers 0 to 8 in order for rows and the 3x3 transpose 036147258 for columns. Adding these in a table modulo 9 gives a valid solution. Classify gets the original ordered range back from the transpose, since all its elements are unique.

9|+⌜⟜⊐⍋3|↕9
         ↕9  # Range 0…8
       3|    # Mod 3: 012012012
      ⍋      # Grade: 036147258
  +⌜⟜        # Addition table with…
     ⊐       #   Classify 012345678
9|           # Modulo 9
History
Why does this post require attention from curators or moderators?
You might want to add some details to your flag.

0 comment threads

+0
−0

Japt, 10 bytes

Outputs a 2D-array.

9õ ñu3
£éX

Try it

9õ ñu3\n£éX
9õ              :Range [1,9]
   ñ            :Sort by
    u3          :  Mod 3 of each
      \n        :Assign to variable U
        £       :Map each X
         éX     :  U rotated right by X
History
Why does this post require attention from curators or moderators?
You might want to add some details to your flag.

0 comment threads

Sign up to answer this question »