Question

Sudoku is a popular number puzzle that appears in many newspapers on a daily basis. The objective of the game (adopted from W

Hi, I don't know how to deal with this python question. Modules are not recommended.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

//Python program

def checkRow(puzzle):
for i in range(9):
rowOccurence = [0,0,0,0,0,0,0,0,0,0]
for j in range(9):
rowOccurence[puzzle[i][j]] += 1
tempRow = rowOccurence[1:10]
for q in range(9):
if tempRow[q] == 1 or tempRow[q] == 0:
continue
else:
return False
return True

def checkColumn(puzzle):
for num in range(9):
colOccurence = [0,0,0,0,0,0,0,0,0,0]
for i in range(9):
colOccurence[puzzle[i][num]] += 1
tempCol = colOccurence[1:10]
for q in range(9):
if tempCol[q] == 1 or tempCol[q] == 0:
continue
else:
return False
return True

def checkSudoku(puzzle):
if len(puzzle) == 9:
numsInRow = 0
for i in range(9):
if len(puzzle[i]) == 9:
numsInRow += 1
if numsInRow == 9:
if checkRow(puzzle):
if checkColumn(puzzle):
return True
else:
return False
else:
return False
else:
return False
else:
return False


print(checkSudoku([[5,3,4,6,7,8,9,1,2],\
[6,7,2,1,9,5,3,4,8],\
[1,9,8,3,4,2,5,6,7],\
[8,5,9,7,6,1,4,2,3],\
[4,2,6,8,5,3,7,9,1],\
[7,1,3,9,2,4,8,5,6],\
[9,6,1,5,3,7,2,8,4],\
[2,8,7,4,1,9,6,3,5],\
[3,4,5,2,8,6,1,7,9] ]))
  
print(checkSudoku([[5,3,4,6,7,8,9,1,2],\
[6,7,2,1,9,5,3,4,8],\
[1,9,8,3,4,2,4,6,7],\
[8,5,9,7,6,1,5,2,3],\
[4,2,6,8,5,3,7,9,1],\
[7,1,3,9,2,4,8,5,6],\
[9,6,1,5,3,7,2,8,4],\
[2,8,7,4,1,9,6,3,5],\
[3,4,5,2,8,6,1,7,9] ]))

//screenShots

main.py 1 def checkRow (puzzle): 3 5 for i in range(9): rowOccurence [e,e,0,0,0,0,e,0,0,0] for J in range(9 rowOccurence[puzzmain.DV 27 def checkSudoku (puzzle): 28 29 if len(puzzle) 9: um s InRow = 0 for i in range (9): if I (puzzle[i]) -9: 32 if chmain.py 45 46 print (checkSudoku( [05,3,4,6,7,8,9,1,2],1 48 49 50 [6,7,2,1,9,5,3,4,8], [1,9,8,3,4,2,5,6,7]八 [8,5,9,7,6,1,4,2,

Add a comment
Know the answer?
Add Answer to:
Hi, I don't know how to deal with this python question. Modules are not recommended. Sudoku...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • A Sudoku puzzle consists of a 9 x9 grid which holds the numbers 1-9 in each...

    A Sudoku puzzle consists of a 9 x9 grid which holds the numbers 1-9 in each space.The objective is to fill the grid with digits so that each column, each row, and each of the nine 3x3 sub-grids that compose the grid contain all of the digits from 1 to 9 (with no repeats). You are to write a recursive method that will construct a valid solution to the puzzle and return that solution. You may construct as many additional...

  • C language Credit for work. Please design a multithreaded application in C with Pthreads - it...

    C language Credit for work. Please design a multithreaded application in C with Pthreads - it determines whether the solution to a Sudoku puzzle is valid. Validate two puzzles In your program, please hard-code the following two 9x9 grids (say in two variables puzzle1 and puzzle2), and determine if each solution is valid. While each grid should be validated by multiple parallel threads, you can validate puzzle1 and then puzzle2 in sequential order (as illustrated) by a single invocation of...

  • Starting code: #include <stdio.h> #include <stdbool.h> #include <assert.h> bool checkSudoku(int sudoku[9][9]) { //code goes here }...

    Starting code: #include <stdio.h> #include <stdbool.h> #include <assert.h> bool checkSudoku(int sudoku[9][9]) { //code goes here } int main() { int sudoku[9][9] = {{7, 3, 5, 6, 1, 4, 8, 9, 2}, {8, 4, 2, 9, 7, 3, 5, 6, 1}, {9, 6, 1, 2, 8, 5, 3, 7, 4}, {2, 8, 6, 3, 4, 9, 1, 5, 7}, {4, 1, 3, 8, 5, 7, 9, 2, 6}, {5, 7, 9, 1, 2, 6, 4, 3, 8}, {1, 5, 7, 4,...

  • Write a JAVA program to solve a sudoku! Given a partially filled 9×9 2D array ‘grid[9][9]’,...

    Write a JAVA program to solve a sudoku! Given a partially filled 9×9 2D array ‘grid[9][9]’, the goal is to assign digits (from 1 to 9) to the empty cells so that every row, column, and subgrid of size 3×3 contains exactly one instance of the digits from 1 to 9. I have posted 3 input files: sudoku1.txt, sudoku2.txt and sudoku3.txt Problem Analysis & Design - Think about how you will need to solve this problem. You should do an...

  • * Your goal in this exercise is to practice recursion and * to see how a...

    * Your goal in this exercise is to practice recursion and * to see how a properly written recursive solution can * take care of fairly complicated tasks with a few lines * of (well thought out) code. * * We will be solving Sudoku puzzles. In case you have never * solved or seen a Sudoku, you can learn more about them * here: * * https://en.wikipedia.org/wiki/Sudoku * * Your task if to write a function that takes an...

  • Programming Language: JAVA Construct a program that uses an agent to solve a Sudoku puzzle as...

    Programming Language: JAVA Construct a program that uses an agent to solve a Sudoku puzzle as a Constraint Satisfaction Problem, with the following guidelines: 1. Since 3 x 3 puzzles are too trivial for a computer, your program should use 4 x 4 puzzles (also known as Super Sudoku puzzles; see Figure 2 for an example). 2. The program should read a Sudoku puzzle from a text file. The user should be able to browse the file system to select...

  • Need help with java In this program you will use a Stack to implement backtracking to solve Sudok...

    need help with java In this program you will use a Stack to implement backtracking to solve Sudoku puzzles. Part I. Implement the stack class.  Created a generic, singly-linked implementation of a Stack with a topPtr as the only instance variable. Implement the following methods only: public MyStack() //the constructor should simply set the topPtr to null public void push(E e) public E pop()  Test your class thoroughly before using it within the soduku program Part II. Create...

  • Do the following project: Following is the file to be programmed in Linux kernel. Run this...

    Do the following project: Following is the file to be programmed in Linux kernel. Run this program. Include the screenshot of the results. Multi threaded Sorting Application Write a multithreaded sorting program that works as follows: A list of integers is divided into two smaller lists of equal size. Two separate threads (which we will term sorting threads) sort each sub list using a sorting algorithm of your choice. The two sub lists are then merged by a third thread—a...

  • How can we assess whether a project is a success or a failure? This case presents...

    How can we assess whether a project is a success or a failure? This case presents two phases of a large business transformation project involving the implementation of an ERP system with the aim of creating an integrated company. The case illustrates some of the challenges associated with integration. It also presents the obstacles facing companies that undertake projects involving large information technology projects. Bombardier and Its Environment Joseph-Armand Bombardier was 15 years old when he built his first snowmobile...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT