Back
Close

Sudoku Solver

Statement

 Goal

Your program must output a solution to a 9x9 sudoku. A sudoku is a Latin Square which has the numbers 1-9 in each row, column, and 3x3 square.
Input
First 9 lines: A string line with 9 digits corresponding to that line. A 0 is used for an empty space.
Output
First 9 lines: A string line with 9 digits corresponding to that line. The original numbers should not have changed, and there should be no zeros left.
Constraints
Example
Input
120070560
507932080
000001000
010240050
308000402
070085010
000700000
080423701
034010028
Output
123874569
567932184
849651237
916247853
358196472
472385916
291768345
685423791
734519628

Tags
Backtracking

Difficulty
Medium

Test cases
Very Easy Test
Input
120070560 507932080 000001000 010240050 308000402 070085010 000700000 080423701 034010028
Output
123874569 567932184 849651237 916247853 358196472 472385916 291768345 685423791 734519628

Very Easy Validator
Input
001065037 300029160 064000000 028004003 000107000 500200690 400000520 756942018 910580000
Output
891465237 375829164 264371985 128694753 639157842 547238691 483716529 756942318 912583476

Easy Test
Input
000700040 020801900 000000173 102006097 600090001 970100405 354000000 008604030 010003000
Output
531769248 427831956 869425173 182546397 645397821 973182465 354278619 798614532 216953784

Easy Validator
Input
000260701 680070090 190004500 820100040 004602900 050003028 009300074 040050036 703018000
Output
435269781 682571493 197834562 826195347 374682915 951743628 519326874 248957136 763418259

Intermediate/Hard Test
Input
006000050 003700000 700035008 000070012 000942000 620080000 900120003 000003600 050000700
Output
816294357 543718269 792635148 438576912 175942836 629381475 964127583 287453691 351869724

Intermediate/Hard Validator
Input
002905000 000006003 701008400 000700004 096300000 000001200 000000002 000080390 350000000
Output
832945617 945176823 761238459 518762934 296354781 473891265 689413572 124587396 357629148

World's Hardest Sudoku Test
Input
800000000 003600000 070090200 050007000 000045700 000100030 001000068 008500010 090000400
Output
812753649 943682175 675491283 154237896 369845721 287169534 521974368 438526917 796318452

World's Hardest Sudoku Validator
Input
800000000 003600000 070090200 050007000 000045700 000100030 001000068 008500010 090000400
Output
812753649 943682175 675491283 154237896 369845721 287169534 521974368 438526917 796318452

Solution language

Solution

Stub generator input