# Sudoku X

Place the numbers 1-6 once in every row, column, diagonal, and 3x2 block. The diagonals form an X and are highlighted.

# Text of puzzle

-----------------
| . . . | 5 . . |
| . . . | . . . |
-----------------
| 1 . . | 4 . . |
| . . 3 | . . . |
-----------------
| . . . | . . . |
| . . . | . . 6 |
-----------------

Can you solve it?

• what exactly is the question?? – Sid Jul 5 '16 at 12:43
• You should find different numbers which aren't the same vertically , horizontally and in the figure of x (edge to edge) – user22143 Jul 5 '16 at 12:49
• Update the question to state the purpose. Are you looking for help, or are you just posting this puzzle to solve? – LeppyR64 Jul 5 '16 at 12:51
• It is so first time i am using this programm – user22143 Jul 5 '16 at 12:53
• @user22143 Welcome to Puzzling.SE! You need to slow down. :) When posting a puzzle it is important to note all of the details required as well as what the objective is. You did not do that. If you look at my edits to your post you can see what a well formatted post is. Secondly, don't be offended by comments and get argumentative. The people posting the comments genuinely want to solve your problem and are frustrated because they don't have enough information. Good luck, and again, welcome! – LeppyR64 Jul 5 '16 at 13:11

Solution:

-----------------
| 4 1 6 | 5 3 2 |
| 2 3 5 | 6 1 4 |
-----------------
| 1 5 2 | 4 6 3 |
| 6 4 3 | 1 2 5 |
-----------------
| 3 6 4 | 2 5 1 |
| 5 2 1 | 3 4 6 |
-----------------

• Oh, didn't see the answer, weird. – Jonathan Allan Jul 5 '16 at 13:42
• @JonathanAllan At least we got the same answer :) – LeppyR64 Jul 5 '16 at 13:43
• Verified, only solution :) – Jonathan Allan Jul 5 '16 at 13:57

I find that the solution is:

+-------+-------+
| 4 1 6 | 5 3 2 |
| 2 3 5 | 6 1 4 |
+-------+-------+
| 1 5 2 | 4 6 3 |
| 6 4 3 | 1 2 5 |
+-------+-------+
| 3 6 4 | 2 5 1 |
| 5 2 1 | 3 4 6 |
+-------+-------+

I have also written some Python code to check and found that it is indeed the only solution:

def initBoard():
return [[0,0,0,5,0,0], [0,0,0,0,0,0], [1,0,0,4,0,0], [0,0,3,0,0,0], [0,0,0,0,0,0], [0,0,0,0,0,6]]

def solveBoard(board, r=0, c=0):
if r==5 and c==5:
for solution in genNext(board, r, c):
yield solution
else:
if c == 5:
nr = r+1
nc = 0
else:
nr = r
nc = c + 1
for nextBoard in genNext(board, r, c):
for solution in solveBoard(nextBoard, nr, nc):
yield solution

def genNext(board, r, c):
if board[r][c]:
yield board
else:
for i in range(1,7):
newBoard = [[i if ci==c else v for ci, v in enumerate(row)] if ri==r else list(row) for ri, row in enumerate(board)]
if isValid(newBoard):
yield newBoard

def isValid(board):
s = set()
for row in board:
for v in row:
if v:
if v in s:
return False
s.clear()
for c in range(6):
for row in board:
v = row[c]
if v:
if v in s:
return False
s.clear()
for r in range(6):
v = board[r][5-r]
if v:
if v in s:
return False
s.clear()
for r in range(6):
v = board[r][r]
if v:
if v in s:
return False
s.clear()
for br in range(0,6,2):
for bc in range(0,6,3):
for r in (br, br+1):
for c in (bc, bc+1, bc+2):
v = board[r][c]
if v:
if v in s:
return False
s.clear()
return True

def printBoard(board):
print('\n'.join(' '.join(str(v) for v in row) for row in board) + '\n')


Running it like so:

>>> for sln in solveBoard(b):
...     printBoard(sln)

• I didn't know that we can solve it with the aid of programming – user22143 Jul 5 '16 at 14:16
• Yes, the program is just pure brute force, but works very quickly! – Jonathan Allan Jul 5 '16 at 14:19
• @JonathanAllan +1 for that code – Adit Kirtani Jul 5 '16 at 16:21