Search code, repositories, users, issues, pull requests...

Provide feedback.

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly.

To see all available qualifiers, see our documentation .

  • Notifications

ntcuong2103/sudoku-assignment

Folders and files, repository files navigation, sudoku assignment.

Build sudoku solver using C programming language.

Reference solver

Learning objectives

  • Practice programming skills
  • Manage pointers, memory, references, structures

Students need to implements the following three algorithms. There are some functions you may need to use such as:

Hidden singles

Read: Hidden singles

Hint: You try use the sudoku solver , pick the example "Gentle" and run step by step. When hidden singles are detected, the message shows the explanation for hidden singles.

Hidden singles detected

Naked pair/triple

  • Read: Naked pair/triple

Hidden pair/triple

  • Read: Hidden pair/triple

Overview of the sample code

Sample code present the base structure for a sudoku board, consisting 9x9 cells arranged in a two-dimensional array.

  • Constraints in sudoku: the digit in each cell is unique in a row, a column and a box where it is belong to.

Sudoku board structure:

  • Row pointers, collumn pointers and boxes pointers: we have 9 rows, 9 collumns and 9 boxes where each consist of an array of 9 pointers refer to the cells of the board.

Cell structure

  • Each cell has an array of 9 integers representing the possible values (candidates). In this array, value could be 1 or 0, indicates that a candidate is existed or not. Note that the index of array is from 0 -> 8, different from 1 -> 9 of the possible values. Then, in the set and unset functions we have:

Evaluation focus on correct implementation of the algorithms, therefore it would check:

  • The number of found cases (number of hidden singles, number of naked pairs, naked tripples, ... ).
  • The remaining candidates after each algorithms is applied.

Scoring rubrics

Scale of 10 points:

  • Test cases with hidden singles (6 pts)
  • Test cases with naked pairs/triples (2 pts)
  • Test cases with hidden pairs/triples (2 pts)

Update the latest version assignments

  • The latest repository is updated on this github link https://github.com/ntcuong2103/sudoku-assignment

To update the latest code:

  • Add the remote repository
  • Pull the code
  • Push to remote repository git push origin --force

Compile, run, debug

Compile using make.

  • Build the executable file
  • Clean built files
  • To add more source files (ex. naked_pairs.c), modify Makefile in the following line:

This will trigger the compilation of naked_pairs.c -> nake_pair.o and added this object file to build the sudoku executable file.

Run program

  • Run with input argument: initial sudoku board (string of 81 digits)
  • Install c/c++ extension pack
  • Add debugging configuration

Modify launch.json

Press F5 for running debugger

Debug test case with autograder

where there are three arguments (args) must be provided: board_input, method, and pipe. Pipe could be set to 0, board_input and method can be get from traces.json

Run test cases

  • Run all the test cases
  • Run range of test cases, for example 0 -> 5
  • Run single test case, for example 5

Input and expected output

The input string and expected output string represent the sudoku board with candidates. You can import it directly to the sudoku solver -> "Import a sudoku" to check the step.

  • Python 21.8%
  • Makefile 12.0%
  • CIS 521 - Artificial Intelligence
  • skeleton file
  • test puzzles (zip file)
  • test puzzle solutions (PDF file)
  • 1_million_sudoku

Homework 5: Sudoku

Instructions.

In this assignment, you will implement three inference algorithms for the popular puzzle game Sudoku.

A skeleton file sudoku.py containing empty definitions for each question has been provided. Since portions of this assignment will be graded automatically, none of the names or function signatures in this file should be modified. However, you are free to introduce additional variables or functions if needed.

You may import definitions from any standard Python library, and are encouraged to do so in case you find yourself reinventing the wheel. If you are unsure where to start, consider taking a look at the data structures and functions defined in the collections , copy , and itertools modules.

You will find that in addition to a problem specification, most programming questions also include one or two examples from the Python interpreter. In addition to performing your own testing, you are strongly encouraged to verify that your code gives the expected output for these examples before submitting.

It is highly recommended that you follow the Python style guidelines set forth in PEP 8 , which was written in part by the creator of Python. However, your code will not be graded for style.

Once you have completed the assignment, you should submit your file on Gradescope . You may submit as many times as you would like before the deadline, but only the last submission will be saved.

1. Sudoku Solver [75 points]

In the game of Sudoku, you are given a partially-filled $9 \times 9$ grid, grouped into a $3 \times 3$ grid of $3 \times 3$ blocks. The objective is to fill each square with a digit from 1 to 9, subject to the requirement that each row, column, and block must contain each digit exactly once.

In this section, you will implement the AC-3 constraint satisfaction algorithm for Sudoku, along with two extensions that will combine to form a complete and efficient solver.

A number of puzzles have been made available on the course website for testing, including:

An easy-difficulty puzzle: easy.txt .

Four medium-difficulty puzzles: medium1.txt , medium2.txt , medium3.txt , and medium4.txt .

Two hard-difficulty puzzles: hard1.txt and hard2.txt .

The examples in this section assume that these puzzle files have been placed in a folder named sudoku located in the same directory as the homework file.

An example puzzle originally from the Daily Pennsylvanian, available as medium1.txt , is depicted below.

[3 points] In this section, we will view a Sudoku puzzle not from the perspective of its grid layout, but more abstractly as a collection of cells. Accordingly, we will represent it internally as a dictionary mapping from cells, i.e. (row, column) pairs, to sets of possible values. This dictionary should have a fixed (9 \times 9=81) set of pairs of keys, but the number of elements in each set corresponding to a key will change as the board is being manipulated.

In the Sudoku class, write an initialization method __init__(self, board) that stores such a mapping for future use. Also write a method get_values(self, cell) that returns the set of values currently available at a particular cell.

In addition, write a function read_board(path) that reads the board specified by the file at the given path and returns it as a dictionary. Sudoku puzzles will be represented textually as 9 lines of 9 characters each, corresponding to the rows of the board, where a digit between "1" and "9" denotes a cell containing a fixed value, and an asterisk "*" denotes a blank cell that could contain any digit.

[2 points] Write a function sudoku_cells() that returns the list of all cells in a Sudoku puzzle as (row, column) pairs. The line CELLS = sudoku_cells() in the Sudoku class then creates a class-level constant Sudoku.CELLS that can be used wherever the full list of cells is needed. Although the function sudoku_cells() could still be called each time in its place, that approach results in a large amount of repeated computation and is therefore highly inefficient. The ordering of the cells within the list is not important, as long as they are all present. (For more information on the difference between class-level constants and fields of a class, see this helpful guide ).

[3 points] Write a function sudoku_arcs() that returns the list of all arcs between cells in a Sudoku puzzle corresponding to inequality constraints. In other words, each arc should be a pair of cells whose values cannot be equal in a solved puzzle. The arcs should be represented a two-tuples of cells, where cells themselves are (row, column) pairs. The line ARCS = sudoku_arcs() in the Sudoku class then creates a class-level constant Sudoku.ARCS that can be used wherever the full list of arcs is needed. The ordering of the arcs within the list is not important, as long as they are all present. Note that this is asking not for the arcs in a particular board, but all of the arcs that exist on an empty board.

[7 points] In the Sudoku class, write a method remove_inconsistent_values(self, cell1, cell2) that removes any value in the set of possibilities for cell1 for which there are no values in the set of possibilities for cell2 satisfying the corresponding inequality constraint (which we have represented as an arc). Each cell argument will be a (row, column) pair. If any values were removed, return True ; otherwise, return False . Note that this question is asking you both to change the class attributes (i.e., change the dictionary representing the board) and to return a boolean value - in Python one can do both in the same method!

Hint: Think carefully about what this exercise is asking you to implement. How many values can be removed during a single invocation of the function?

[10 points] In the Sudoku class, write a method infer_ac3(self) that runs the AC-3 algorithm on the current board to narrow down each cell’s set of values as much as possible. Although this will not be powerful enough to solve all Sudoku problems, it will produce a solution for easy-difficulty puzzles such as the one shown below. By “solution”, we mean that there will be exactly one element in each cell’s set of possible values, and that no inequality constraints will be violated.

[25 points] Consider the outcome of running AC-3 on the medium-difficulty puzzle shown below. Although it is able to determine the values of some cells, it is unable to make significant headway on the rest.

However, if we consider the possible placements of the digit 7 in the upper-right block, we observe that the 7 in the third row and the 7 in the final column rule out all but one square, meaning we can safely place a 7 in the indicated cell despite AC-3 being unable to make such an inference.

In the Sudoku class, write a method infer_improved(self) that runs this improved version of AC-3, using infer_ac3(self) as a subroutine (perhaps multiple times). You should consider what deductions can be made about a specific cell by examining the possible values for other cells in the same row, column, or block. Using this technique, you should be able to solve all of the medium-difficulty puzzles. Note that this goes beyond the typical AC3 approach because it involves constraints that relate more than 2 variables.

[25 points] Although the previous inference algorithm is an improvement over the ordinary AC-3 algorithm, it is still not powerful enough to solve all Sudoku puzzles. In the Sudoku class, write a method infer_with_guessing(self) that calls infer_improved(self) as a subroutine, picks an arbitrary value for a cell with multiple possibilities if one remains, and repeats. You should implement a backtracking search which reverts erroneous decisions if they result in unsolvable puzzles. For efficiency, the improved inference algorithm should be called once after each guess is made. This method should be able to solve all of the hard-difficulty puzzles, such as the one shown below.

We provided a GUI for you to test your algorithms. The interface is shown below. You could try different solvers you implemented and reset the puzzle using the text input. The text input allows for two different puzzle formats (empty block with ‘*’ or ‘0’). You could just directly copy and paste from the given text and csv file to reset the puzzle.

Feedback [5 points]

[1 point] Approximately how many hours did you spend on this assignment?

[2 point] Which aspects of this assignment did you find most challenging? Were there any significant stumbling blocks?

[2 point] Which aspects of this assignment did you like? Is there anything you would have changed?

15-200 Fall 2006 Homework Assignment 9 Sudoku

Objectives:, instructions:, extra credit:, what you'll need:.

  • Sudoku.java
  • Solver.java

Handing in your Solution:

ftp your solution to /afs/andrew/course/15/200/www/handin

Sudoku Assignment

Implement a Sudoku solver that works on an empty or partially-filled board.

Your solver should at least work on a board with 3 x 3 sub-grids (81 cells total), but ideally should be parameterized over the width and height of each sub-grid.

Your implementation should find a solution, if one exists, for any given partially filled board. Optionally, it should report the number of solutions that exit.

55 US Coast Guard cadets disciplined after cheating scandal for copying homework answers

Officials said the 55 second class cadets distributed answers for two separate homework assignments via electronic means and were disciplined..

coursework assignment sudoku assignment

Dozens of United States Coast Guard Academy cadets have been disciplined following a cheating scandal in which officials this week announced they copied each other's work on assignments, violating the academy's policy.

According to a press releas e from the military force of maritime professionals, 55 Second Class cadets distributed answers for two separate homework assignments via electronic means.

Details of each cadet’s respective involvement in the scheme were investigated and reviewed during a series of hearings at the academy, the release states, and each cadet was punished "on a case-by-case basis."

The academy is in New London, Connecticut, a coastal city west of the Rhode Island border.

The U.S. Coast Guard is one of the nation's six armed forces and, according to its website, the only military branch in the nation's Department of Homeland Security.

'Crushed': Grateful Dead music fest canceled with no refunds 10 days before event

What happened to the US Coast Guard cadets who cheated?

Consequences of their reported cheating include:

  • Six cadets failed the course
  • Forty eight cadets received lowered grades
  • Eleven cadets were removed from their summer battalion command positions

All 55 cadets are required to undergo a 20-week honor remediation program, the release continues, and will be restricted to the academy.

Cadets involved in cheating scandal permitted to appeal discipline

The cadets can appeal their respective disciplinary actions.

“The U.S. Coast Guard Academy is committed to upholding the highest standards of integrity, honor, and accountability,” Capt. Edward Hernaez, Commandant of Cadets released in statement. “Misconduct like this undermines trust and those found to have violated our principles were held accountable for their actions.”

Natalie Neysa Alund is a senior reporter for USA TODAY. Reach her at [email protected] and follow her on X @nataliealund.

55 Coast Guard Academy cadets disciplined over homework cheating accusations

FILE - The United States Coast Guard Academy is seen, Sept. 14, 2020, in New London, Conn. Fifty-five U.S. Coast Guard Academy cadets have been disciplined for sharing homework answers in violation of academy policy, Coast Guard officials announced. (AP Photo/Jessica Hill, File)

  • Show more sharing options
  • Copy Link URL Copied!

Fifty-five U.S. Coast Guard Academy cadets have been disciplined for sharing homework answers in violation of academy policy, Coast Guard officials announced.

After a series of disciplinary hearings, six of the cadets failed the course and 48 got lowered grades, officials said Wednesday.

The cadets were accused of cheating by sharing answers for two separate homework assignments electronically.

“The U.S. Coast Guard Academy is committed to upholding the highest standards of integrity, honor, and accountability,” said Capt. Edward Hernaez, commandant of the academy. “Misconduct like this undermines trust and those found to have violated our principles were held accountable for their actions.”

The cadets will be provided the opportunity to appeal the disciplinary actions, officials said.

Top headlines by email, weekday mornings

Get top headlines from the Union-Tribune in your inbox weekday mornings, including top news, local, sports, business, entertainment and opinion.

You may occasionally receive promotional content from the San Diego Union-Tribune.

More in this section

FILE - Los Angeles Dodgers' Shohei Ohtani, right, and his interpreter, Ippei Mizuhara, leave after a news conference ahead of a baseball workout at Gocheok Sky Dome in Seoul, South Korea, March 16, 2024. The former longtime interpreter for Los Angeles Dodgers star Shohei Ohtani has been charged with federal bank fraud for crimes involving gambling debts and theft of millions of dollars from the slugger. Federal authorities announced the development Thursday, April 11, at a press conference in Los Angeles. (AP Photo/Lee Jin-man, File)

Nation-World

Judge in sports betting case orders ex-interpreter for Ohtani to get gambling addiction treatment

Judge in sports betting case orders ex-interpreter for Shohei Ohtani to get gambling addiction treatment

Former US ambassador sentenced to 15 years in prison for serving as secret agent for Cuba

A former career U.S. diplomat has been sentenced to 15 years in federal prison after admitting he worked for decades as a secret agent for communist Cuba

Former Philadelphia 76ers NBA basketball player Allen Iverson poses for photos next to his statue at the teams training center in Camden, N.J., Friday, April 12, 2024 (Jose F. Moreno/The Philadelphia Inquirer via AP)

Allen Iverson immortalized with sculpture alongside 76ers greats Julius Erving and Wilt Chamberlain

The Philadelphia 76ers unveiled a sculpture of Allen Iverson at their practice facility on Friday

Judge orders ex-interpreter for baseball star Shohei Ohtani to do gambling addiction treatment in sports betting case

President Joe Biden speaks to the National Action Network Convention remotely from the South Court Auditorium of the White House, Friday, April 12, 2024, in Washington. (AP Photo/Alex Brandon)

Biden tells racial justice meeting, ‘We’ve kept our promises,’ as he looks to energize Black voters

President Joe Biden has virtually addressed the Rev. Al Sharpton’s racial justice conference, telling a sympathetic crowd “we’ve kept our promises” as he ramps up efforts to energize Black voters who will be vital to his reelection bid this fall

Sheriff believes body in burned SUV to be South Florida woman who went missing after carjacking

Authorities in central Florida say they believe they’ve found the body of a South Florida woman who was taken in a carjacking

IMAGES

  1. Presentation

    coursework assignment sudoku assignment

  2. Solved sudoku.pdf Coursework Assignment. Sudoku assignment

    coursework assignment sudoku assignment

  3. Coursework Assignment: Sudoku Assignment: Background: Sudoku and

    coursework assignment sudoku assignment

  4. Sudoku Game Board Creation

    coursework assignment sudoku assignment

  5. Presentation

    coursework assignment sudoku assignment

  6. A1b

    coursework assignment sudoku assignment

VIDEO

  1. SWE Coursework Assignment 1

  2. Cuu coursework assignment 1

  3. Final Coursework: An image processing application

  4. Abusa Michael 2301200740 Review Assignment ppt

  5. ARC consistency explanation and Assignment of Sudoku

COMMENTS

  1. Solved Coursework Assignment: Sudoku assignment Algorithms

    The 9 tasks in this assignment make up the Sudoku coursework assignment. The tasks in this assignment consist, in the main, of functions or lines of code to be written in pseudocode. Because your solutions should be written in pseudocode, marks will not be deducted for small syntax errors as long as the pseudocode can be understood by a human. ...

  2. PDF Homework 7: Sudoku

    Homework 7: Sudoku For this assignment, you will write a Sudoku solver. To do so, you will (1) use Scala collections extensively, (2) implement a backtracking search algorithm, and (3) implement constraint propagation. Preliminaries We assume you know how to play Sudoku. If you don't, you should play a few games by hand, before attempting

  3. PDF CSC384 Assignment 1 : Sudoku

    for the first assignment of the course. Puzzle Background The Sudoku puzzle is a 9x9 grid of squares, some of which contain number values from the start. Your goal is to add additional digits so that each row, column and 3x3 square contains the digits 1 to 9, inclusive. Solving Sudoku The brute force method of solving Sudoku involves a pencil ...

  4. Algorithms and Data Structures

    Coursework Assignment: Sudoku assignment Algorithms and Data Structure I The 10 tasks in this assignment make up the Sudoku coursework assignment. The tasks in this assignment consist, in the main, of functions or lines of code to be written in pseudocode. Because your solutions should be written in pseudocode, marks will not be deducted for small syntax errors as long as the pseudocode can be ...

  5. GitHub

    Sample code present the base structure for a sudoku board, consisting 9x9 cells arranged in a two-dimensional array. Constraints in sudoku: the digit in each cell is unique in a row, a column and a box where it is belong to.

  6. PDF Assignment #2: Sudoku (Constraint Satisfaction Problems)

    program using CSP solution techniques to solve Sudoku puzzles. As a reminder, a Sudoku puzzle is a 9x9 grid (81 variables) where each cell in the grid can take on the integer values 1-9 (the domain of each variable). A solution to a Sudoku puzzle is an assignment of values for each cell in the grid such that no two cells in the same row, column, or

  7. rKWE7f-pS3OlhO3 qbtzYQ 054b23e1efcc4341a2f2221f6aa1efe1 ...

    Coursework Assignment: Sudoku assignment Algorithms and Data Structure I The 10 tasks in this assignment make up the Sudoku coursework assignment. The tasks in this assignment consist, in the main, of functions or lines of code to be written in pseudocode. Because your solutions should be written in pseudocode, marks will not be deducted for small syntax errors as long as the pseudocode can be ...

  8. Algorithms and Data Structures

    Mid-term Assessment: Sudoku assignment Algorithms and Data Structure I There are 10 tasks in this assignment. The tasks consist, in the main, of functions to be written in pseudocode. For those specific tasks asking for functions should be written in pseudocode, and no explanation of the pseudocode is needed. Because your solutions should be written in pseudocode, marks will not be deducted ...

  9. Solving Sudoku puzzles: nifty course assignments

    This type of puzzle is a good assignment candidate for use when teaching arrays and functions in a CS1 course. In an object oriented course, the puzzle may also be used to teach design patterns such as Visitor.There are several possibilities for coursework. The student could create a Sudoku solution verifier or write a simple puzzle solver.

  10. CIS 521 Homework 5 "Sudoku Solver"

    Homework 5: Sudoku Instructions. In this assignment, you will implement three inference algorithms for the popular puzzle game Sudoku. A skeleton file sudoku.py containing empty definitions for each question has been provided. Since portions of this assignment will be graded automatically, none of the names or function signatures in this file should be modified.

  11. Solved it is the Sudoku coursework assignment. The tasks in

    it is the Sudoku coursework assignment. The tasks in this assignment consist, in the main, of functions or lines of code to be written in pseudocode. and the solutions should be written in pseudocode. please write in pseudocode only. There are 2 steps to solve this one.

  12. 15-200: Sudoku

    In this assignment you will write a program to solve Sudoku logical puzzles that currently taking the world by storm! A puzzle consists of a grid of size 9x9 divided into 9 subgrids of size 3x3. Some of the grid cells are filled with numbers from 1 to 9. You have to fill in the reamining cells in the grid with numbers from 1 to 9 so that each ...

  13. Coursework Assignment: Sudoku Assignment: Background: Sudoku ...

    Attachment_1641656543 - Free download as PDF File (.pdf), Text File (.txt) or read online for free. Sudoku assignment

  14. Sudoku assignment Task 1 Function...

    View sudoku assignment.pdf from CSC 13116 at San Francisco State University. Sudoku assignment Task 1 Function MAKEVECTOR(row) New vector puzzle(4) For 0 < i ≤ 4 Puzzle[i] = [2,4,1,3] End for Return

  15. Sudoku Assignment

    Sudoku Assignment. Implement a Sudoku solver that works on an empty or partially-filled board. Your solver should at least work on a board with 3 x 3 sub-grids (81 cells total), but ideally should be parameterized over the width and height of each sub-grid. Your implementation should find a solution, if one exists, for any given partially ...

  16. Sudoku Homework Assignment

    This video uses Sudoku puzzle times as a way to introduce the location of a point in a distribution.

  17. Solved it is the Sudoku coursework assignment. The tasks in

    Engineering; Computer Science; Computer Science questions and answers; it is the Sudoku coursework assignment. The tasks in this assignment consist, in the main, of functions or lines of code to be written in pseudocode, and solutions should be written in pseudocode. please write the solution in pseudocode only.

  18. sudoku.pdf

    Coursework: Sudoku assignment Problem Solving for Computer Science The 11 tasks in this assignment make up the Sudoku coursework assignment. Download and open the folder stored in sudoku.zip then change the directory in your CLI to this folder. The tasks in this assignment consist mainly of completing JavaScript functions in the file called ...

  19. Sudoku Assignment

    SUDOKU ASSIGNMENT. Before. After. Solving the Sudoku puzzle became way easier due to the Auto-Check function. However, I think that critical thinking is still applicable because critical thinking only stops when answers are already given in the puzzle. The difficulty I had when solving the puzzle was the first blocks.

  20. Coast Guard Academy cheating scandal: 55 cadets disciplined in fallout

    55 US Coast Guard cadets disciplined over cheating scandal for sharing homework answers Officials said the 55 Second Class cadets distributed answers for two separate homework assignments via ...

  21. a5.pdf

    Assignment 5: Sudoku Assignment evolved at Pomona College through several instructors' offerings, with changes by Nathan Shelly and Sara Sood, Northwestern University. In this assignment, you will build your own Sudoku puzzle solver. We've provided starter code in a file named a5.py. We will represent a state in the sudoku puzzle as a list of 9 lists each with 9 lists inside them.

  22. 55 Coast Guard Academy cadets disciplined over homework cheating

    NEW LONDON, Conn. — Fifty-five U.S. Coast Guard Academy cadets have been disciplined for sharing homework answers in violation of academy policy, Coast Guard officials announced.

  23. Question: The 10 tasks in this assignment make up the Sudoku coursework

    The 10 tasks in this assignment make up the Sudoku coursework assignment. The tasks in this assignment consist, in the main, of functions or lines of code to be written in pseudocode. Because your solutions should be written in pseudocode, marks will not be deducted for small syntax errors as long as the pseudocode can be understood by a human.

  24. Solved The 10 tasks in this assignment make up the Sudoku

    The 10 tasks in this assignment make up the Sudoku coursework assignment. The tasks in this assignment consist. in the main, of functions or lines of code to be written in pseudocode Because your solutions should be written in pseudocode, marks will not be deducted for small syntax errors as long as the pseudocode can be understood by a human.