-3
$\begingroup$

Sudoku X

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

Puzzle

Wiut.uz

Text of puzzle

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

Can you solve it?

$\endgroup$
  • 1
    $\begingroup$ what exactly is the question?? $\endgroup$ – Sid Jul 5 '16 at 12:43
  • $\begingroup$ You should find different numbers which aren't the same vertically , horizontally and in the figure of x (edge to edge) $\endgroup$ – user22143 Jul 5 '16 at 12:49
  • $\begingroup$ Update the question to state the purpose. Are you looking for help, or are you just posting this puzzle to solve? $\endgroup$ – LeppyR64 Jul 5 '16 at 12:51
  • $\begingroup$ It is so first time i am using this programm $\endgroup$ – user22143 Jul 5 '16 at 12:53
  • 2
    $\begingroup$ @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! $\endgroup$ – LeppyR64 Jul 5 '16 at 13:11
5
$\begingroup$

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 |
-----------------

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

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.add(v)
        s.clear()
    for c in range(6):
        for row in board:
            v = row[c]
            if v:
                if v in s:
                    return False
                s.add(v)
        s.clear()
    for r in range(6):
        v = board[r][5-r]
        if v:
            if v in s:
                return False
            s.add(v)
    s.clear()
    for r in range(6):
        v = board[r][r]
        if v:
            if v in s:
                return False
            s.add(v)
    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.add(v)
            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)
$\endgroup$
  • $\begingroup$ I didn't know that we can solve it with the aid of programming $\endgroup$ – user22143 Jul 5 '16 at 14:16
  • 1
    $\begingroup$ Yes, the program is just pure brute force, but works very quickly! $\endgroup$ – Jonathan Allan Jul 5 '16 at 14:19
  • $\begingroup$ @JonathanAllan +1 for that code $\endgroup$ – Adit Kirtani Jul 5 '16 at 16:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.