Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

create function solve sudoku(file name) that finds the solution for the given sudoku. Input: a file name file name, where the file contains n lines,

create function solve sudoku(file name) that finds the solution for the given sudoku.

Input: a file name file name, where the file contains n lines, and each line contains n entries separated by commas. Each entry will either be a positive integer, or the letter 'x'.

Output: a nested list representing a completed sudoku grid. You may assume the file given will always contain exactly one valid solution.

File gridA.txt contains:

x,x,1,x

4,x,x,x

x,x,x,2

x,3,x,x

File gridB.txt contains:

1,x,9,x,x,x,x,6,x

8,4,x,x,1,x,x,7,5

x,x,2,x,x,3,x,x,4

x,x,8,3,2,1,x,4,7

x,x,5,x,x,x,6,x,x

4,2,x,6,9,5,8,x,x

7,x,x,1,x,x,4,x,x

6,9,x,x,8,x,x,5,3

x,5,x,x,x,x,7,x,9

Examples

a) Calling solve sudoku('gridA.txt') returns:

[ [3,2,1,4],

[4,1,2,3],

[1,4,3,2],

[2,3,4,1] ]

b) Calling solve sudoku('gridB.txt') returns:

[ [1, 3, 9, 5, 7, 4, 2, 6, 8],

[8, 4, 6, 9, 1, 2, 3, 7, 5],

[5, 7, 2, 8, 6, 3, 9, 1, 4],

[9, 6, 8, 3, 2, 1, 5, 4, 7],

[3, 1, 5, 7, 4, 8, 6, 9, 2],

[4, 2, 7, 6, 9, 5, 8, 3, 1],

[7, 8, 3, 1, 5, 9, 4, 2, 6],

[6, 9, 4, 2, 8, 7, 1, 5, 3],

[2, 5, 1, 4, 3, 6, 7, 8, 9] ]

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Dental Assisting

Authors: Doni Bird, Debbie Robinson

13th Edition

978-0323624855, 0323624855

Students also viewed these Programming questions