Sudoku Solver

Practice this coding question on Coding Gurukul.

Problem statement

A puzzle magazine has recovered a partially erased Sudoku grid. The surviving clues are reliable, and the editor needs the completed grid before printing. Your task Fill every empty cell with a digit from 1 through 9 to solve the Sudoku. Important details Every row, every column and each of the nine aligned 3 by 3 boxes must contain each digit exactly once. A dot marks an empty cell. Preserve all existing clues. Every supplied board has exactly one solution; an already completed valid board must be printed unchanged. Worked example If the first row is .34678912 and all other rows match the sample solved grid, the missing first cell must be 5: it is the only absent digit in that row and also fits its column and box. The sample output shows the full completed grid.

Input format

Nine lines of nine characters each, using digits 1 through 9 and dots.

Output format

Print nine lines of nine digits each, with no spaces.

Constraints

The board is 9 by 9, its clues are consistent, and exactly one solution exists.

Sample input

.34678912
672195348
198342567
859761423
426853791
713924856
961537284
287419635
345286179

Sample output

534678912
672195348
198342567
859761423
426853791
713924856
961537284
287419635
345286179

Sign in to run or submit a solution in C++, Java or Python.

Loading Coding Gurukul…