Skip to content

Instantly share code, notes, and snippets.

@horaceho
Created January 15, 2025 01:37
Show Gist options
  • Select an option

  • Save horaceho/64f20f71115b6072ee20e1dcfa9cd650 to your computer and use it in GitHub Desktop.

Select an option

Save horaceho/64f20f71115b6072ee20e1dcfa9cd650 to your computer and use it in GitHub Desktop.
Validate Sudoku on DeepSeek V3

Question

Is this a valid sudoku grid:

+-------+-------+-------+
| 7 8 9 | 6 1 2 | 3 4 5 |
| 4 2 3 | 8 7 5 | 6 9 1 |
| 1 5 6 | 4 3 9 | 2 8 7 |
+-------+-------+-------+
| 8 7 2 | 5 4 3 | 9 1 6 |
| 5 3 4 | 1 6 7 | 8 2 9 |
| 6 9 1 | 2 8 4 | 5 7 3 |
+-------+-------+-------+
| 3 4 5 | 7 9 8 | 1 6 2 |
| 9 6 8 | 3 2 1 | 7 5 4 |
| 2 1 7 | 9 5 6 | 4 3 8 |
+-------+-------+-------+

Answer

To determine if the provided Sudoku grid is valid, we need to check three key conditions for each row, column, and 3x3 subgrid:

  1. Rows: Each row must contain the digits 1 through 9 without repetition.
  2. Columns: Each column must contain the digits 1 through 9 without repetition.
  3. Subgrids: Each 3x3 subgrid must contain the digits 1 through 9 without repetition.

Let's analyze the grid step by step.

Step 1: Validate Rows

We'll check each row to ensure all digits from 1 to 9 are present without duplicates.

  • Row 1: 7, 8, 9, 6, 1, 2, 3, 4, 5 → All digits present, no duplicates.
  • Row 2: 4, 2, 3, 8, 7, 5, 6, 9, 1 → All digits present, no duplicates.
  • Row 3: 1, 5, 6, 4, 3, 9, 2, 8, 7 → All digits present, no duplicates.
  • Row 4: 8, 7, 2, 5, 4, 3, 9, 1, 6 → All digits present, no duplicates.
  • Row 5: 5, 3, 4, 1, 6, 7, 8, 2, 9 → All digits present, no duplicates.
  • Row 6: 6, 9, 1, 2, 8, 4, 5, 7, 3 → All digits present, no duplicates.
  • Row 7: 3, 4, 5, 7, 9, 8, 1, 6, 2 → All digits present, no duplicates.
  • Row 8: 9, 6, 8, 3, 2, 1, 7, 5, 4 → All digits present, no duplicates.
  • Row 9: 2, 1, 7, 9, 5, 6, 4, 3, 8 → All digits present, no duplicates.

Conclusion: All rows are valid.

Step 2: Validate Columns

Next, we'll examine each column to ensure they contain all digits from 1 to 9 without repetition.

  • Column 1: 7, 4, 1, 8, 5, 6, 3, 9, 2 → All digits present, no duplicates.
  • Column 2: 8, 2, 5, 7, 3, 9, 4, 6, 1 → All digits present, no duplicates.
  • Column 3: 9, 3, 6, 2, 4, 1, 5, 8, 7 → All digits present, no duplicates.
  • Column 4: 6, 8, 4, 5, 1, 2, 7, 3, 9 → All digits present, no duplicates.
  • Column 5: 1, 7, 3, 4, 6, 8, 9, 2, 5 → All digits present, no duplicates.
  • Column 6: 2, 5, 9, 3, 7, 4, 8, 1, 6 → All digits present, no duplicates.
  • Column 7: 3, 6, 2, 9, 8, 5, 1, 7, 4 → All digits present, no duplicates.
  • Column 8: 4, 9, 8, 1, 2, 7, 6, 5, 3 → All digits present, no duplicates.
  • Column 9: 5, 1, 7, 6, 9, 3, 2, 4, 8 → All digits present, no duplicates.

Conclusion: All columns are valid.

Step 3: Validate 3x3 Subgrids

Finally, we'll check each of the nine 3x3 subgrids to ensure they contain all digits from 1 to 9 without repetition.

Let's label the subgrids for clarity:

Subgrid 1 | Subgrid 2 | Subgrid 3
Subgrid 4 | Subgrid 5 | Subgrid 6
Subgrid 7 | Subgrid 8 | Subgrid 9
  • Subgrid 1:

    7 8 9
    4 2 3
    1 5 6
    

    Digits: 7, 8, 9, 4, 2, 3, 1, 5, 6 → All digits present, no duplicates.

  • Subgrid 2:

    6 1 2
    8 7 5
    4 3 9
    

    Digits: 6, 1, 2, 8, 7, 5, 4, 3, 9 → All digits present, no duplicates.

  • Subgrid 3:

    3 4 5
    6 9 1
    2 8 7
    

    Digits: 3, 4, 5, 6, 9, 1, 2, 8, 7 → All digits present, no duplicates.

  • Subgrid 4:

    8 7 2
    5 3 4
    6 9 1
    

    Digits: 8, 7, 2, 5, 3, 4, 6, 9, 1 → All digits present, no duplicates.

  • Subgrid 5:

    5 4 3
    1 6 7
    2 8 4
    

    Wait, here we see a repetition: the digit 4 appears twice in this subgrid.

    Let's verify:

    5 4 3
    1 6 7
    2 8 4
    

    Digits: 5, 4, 3, 1, 6, 7, 2, 8, 4 → The digit 4 is repeated.

Conclusion: Subgrid 5 is invalid due to the repetition of the digit 4.

Since one of the subgrids fails the validity check, the entire Sudoku grid is invalid.

Final Answer

No, the provided Sudoku grid is not valid. The invalidity arises from Subgrid 5, which contains a duplicate digit 4. For a Sudoku grid to be valid, every row, column, and 3x3 subgrid must contain each digit from 1 to 9 exactly once without any repetitions. In this case, the repetition in Subgrid 5 violates this rule, rendering the entire grid invalid.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment