Getting Started with Adobe After Effects - Part 6: Motion Blur
First Time? You can support us by signing up. It takes only 5 seconds. Click here to sign up. If you already have an account, click here to login.

TSQL Challenge 63 - A TSQL Sudoku

This challenge is a puzzle of numbers. Everyone of you might have came across this puzzle named 'Sudoku'. I usually see it in the daily Newspaper. The puzzle is just a play of numbers from 1 to 9, arranging them in nine boxes in an order such that each number from 1 to 9 exists in each box, column and row.

Database Source Control in just 5 minutes
It takes just 5 minutes to connect your SQL databases to source control. Got 5 minutes to spare? Bring your database development process forward by 5 years. Get started now.

Sample Data

SudokuNo Row Col Data
-------- --- --- ----
	   1   2   1	9
	   1   3   1    2	
	   1   4   1    5	
	   1   6   1    6
	   1   8   1    3	
	   1   9   1    8
	   1   5   2    1
	   1   6   2    3
	   1   8   2    2
	   1   4   3    2
	   1   8   3    4
	   1   9   3    6
	   1   2   4    3	
	   1   5   4    8
	   1   6   4    1
	   1   7   4    2
	   1   3   5    8
	   1   5   5    9
	   1   7   5    4
	   1   3   6    7
	   1   4   6    4
	   1   5   6    5
	   1   8   6    6
	   1   1   7    3
	   1   2   7    5
	   1   6   7    8
	   1   2   8    4
	   1   4   8    1
	   1   5   8    6
	   1   1   9    8
	   1   2   9    2
	   1   4   9    7
	   1   6   9    4
	   1   7   9    5
	   1   8   9    1

The sample input given above represents a sudoku as given below.



Your job is to translate this into a result set that looks like the below illustration.

1 6 5 4 2 9 3 7 8
9 7 8 3 6 1 5 4 2
2 4 3 5 8 7 1 9 6
5 8 2 6 3 4 9 1 7
4 1 7 8 9 5 2 6 3
6 3 9 1 7 2 8 5 4
7 9 1 2 4 8 6 3 5
3 2 4 9 5 6 7 8 1
8 5 6 7 1 3 4 2 9

Expected Results

SudokuNo Row/Col 1  2  3  4  5  6  7  8  9
-------- ------- -- -- -- -- -- -- -- -- --
	   1	   1  1  6  5  4  2  9  3  7  8 
	   1	   2  9  7  8  3  6  1  5  4  2 
	   1	   3  2  4  3  5  8  7  1  9  6 
	   1       4  5  8  2  6  3  4  9  1  7 
	   1       5  4  1  7  8  9  5  2  6  3 
	   1       6  6  3  9  1  7  2  8  5  4 
	   1       7  7  9  1  2  4  8  6  3  5 
	   1       8  3  2  4  9  5  6  7  8  1 
	   1       9  8  5  6  7  1  3  4  2  9

Rules

  1. SudokuNo is the Sudoku puzzle number. There can be more than one Sudoku puzzles for input.
  2. Row and Column defines the row and column number where the data is located.
  3. Output should be a 9 X 9 table showing the row and column number along with the Sudoku puzzle number.
  4. The 9 X 9 table consists of nine 3 X 3 boxes each of which should have the number 1 to 9 with each number occurring only once.
  5. Each row and column should have the numbers 1 to 9 with each number occurring only once.
  6. The sudoku data will be such that there is only one solution for each puzzle. This means at least 17 clues will always be present in the data.
  7. The output should be ordered by SudokuNo, Row/Col number.

Sample Script

Use the TSQL Script given below to generate the source table and fill them with sample data.

IF OBJECT_ID('TC63','U') IS NOT NULL BEGIN
	DROP TABLE TC63
END
GO

CREATE TABLE TC63(
	SudokuNo INT,
	Row INT,
	Col INT,
	Data INT
)
GO

INSERT INTO TC63(SudokuNo,Row,Col,Data)
SELECT 1,2,1,9 UNION ALL
SELECT 1,3,1,2 UNION ALL
SELECT 1,4,1,5 UNION ALL
SELECT 1,6,1,6 UNION ALL
SELECT 1,8,1,3 UNION ALL
SELECT 1,9,1,8 UNION ALL
SELECT 1,5,2,1 UNION ALL
SELECT 1,6,2,3 UNION ALL
SELECT 1,8,2,2 UNION ALL
SELECT 1,4,3,2 UNION ALL
SELECT 1,8,3,4 UNION ALL
SELECT 1,9,3,6 UNION ALL
SELECT 1,2,4,3 UNION ALL
SELECT 1,5,4,8 UNION ALL
SELECT 1,6,4,1 UNION ALL
SELECT 1,7,4,2 UNION ALL
SELECT 1,3,5,8 UNION ALL
SELECT 1,5,5,9 UNION ALL
SELECT 1,7,5,4 UNION ALL
SELECT 1,3,6,7 UNION ALL
SELECT 1,4,6,4 UNION ALL
SELECT 1,5,6,5 UNION ALL
SELECT 1,8,6,6 UNION ALL
SELECT 1,1,7,3 UNION ALL
SELECT 1,2,7,5 UNION ALL
SELECT 1,6,7,8 UNION ALL
SELECT 1,2,8,4 UNION ALL
SELECT 1,4,8,1 UNION ALL
SELECT 1,5,8,6 UNION ALL
SELECT 1,1,9,8 UNION ALL
SELECT 1,2,9,2 UNION ALL
SELECT 1,4,9,7 UNION ALL
SELECT 1,6,9,4 UNION ALL
SELECT 1,7,9,5 UNION ALL
SELECT 1,8,9,1 

SELECT * FROM TC63

Restrictions

  1. This challenge allows multi-statement solutions. Your solution does not need to be a single-query solution.
  2. You can use RBAR, cursors, loops etc in your solution. However, we need to apply some restrictions on your code so that your solution can be evaluated using our automated evaluation script. Your code should not create objects like views, functions or stored procedures. Your solution should be a single batch. There should not be any 'GO' statements between your solution. We will put the entire content of your solution to the body of a stored procedure and if we do that, your code should not produce an error. For example, you need to make sure that the following works:
    CREATE PROCEDURE TC_Eval
    AS
    BEGIN
    SET NOCOUNT ON
    -- your code here
    END
    GO
    
    Your code should not include the code to create the sample data. You can assume that the sample tables already exist in the current database.

Notes

  1. Read the Submission Guidelines and make sure that your solution follows them.
  2. If you would like to use a Tally Table, you can use the script given here. Your solution should not include the script to create and populate the tally table. You can assume that the tally table will be available in the database where the evaluation team will run your Code.
Database Source Control in just 5 minutes
It takes just 5 minutes to connect your SQL databases to source control. Got 5 minutes to spare? Bring your database development process forward by 5 years. Get started now.

Divya Agrawal Shah
88 · 2% · 629
Submit a Solution
Previous Challenge
Next Challenge
9
Liked
37
Comments
45
Solutions



Submit

TSQL Challenge 63 - A TSQL Sudoku

Managed Windows Shared Hosting by OrcsWeb

Copyright © Rivera Informatic Private Ltd.