COSC 130 - Project 03

Kyle Anderson

Introduction

We will be by running the script in which you have created the functions that you will be using.

In [3]:
%run -i Sudoku.py

Puzzle 1

In [4]:
puzzle01 = load_puzzle('puzzle01.txt')

display_puzzle(puzzle01)
Sudoku loaded from puzzle01.txt 

+-------+-------+-------+
| 5 . . | . . . | . . . |
| . 9 . | 7 . . | 8 . . |
| . . . | . 3 . | . 7 . |
+-------+-------+-------+
| 6 . 1 | . . . | 9 8 . |
| . . . | 6 . . | . . . |
| . . 9 | . . . | 7 . 1 |
+-------+-------+-------+
| . . . | . . 8 | 1 9 . |
| . 4 . | 5 . 1 | . . 8 |
| . 7 . | 3 . 6 | . 4 . |
+-------+-------+-------+

Now you will now attempt to find a solution to the puzzle

In [5]:
solve(puzzle01)
if solve(puzzle01) is None:
    print("No solution exists for this puzzle.")
else:
    display_puzzle(solve(puzzle01))
+-------+-------+-------+
| 5 1 7 | 9 8 4 | 3 2 6 |
| 4 9 3 | 7 6 2 | 8 1 5 |
| 8 2 6 | 1 3 5 | 4 7 9 |
+-------+-------+-------+
| 6 3 1 | 2 5 7 | 9 8 4 |
| 7 8 4 | 6 1 9 | 2 5 3 |
| 2 5 9 | 8 4 3 | 7 6 1 |
+-------+-------+-------+
| 3 6 5 | 4 2 8 | 1 9 7 |
| 9 4 2 | 5 7 1 | 6 3 8 |
| 1 7 8 | 3 9 6 | 5 4 2 |
+-------+-------+-------+

Puzzle 2

In [6]:
puzzle02 = load_puzzle('puzzle02.txt')

display_puzzle(puzzle02)
Sudoku loaded from puzzle02.txt 

+-------+-------+-------+
| . 6 7 | . 9 . | 4 . . |
| 9 . . | 4 . . | . . . |
| . 3 . | . . . | 1 5 . |
+-------+-------+-------+
| . . . | . 2 . | . . . |
| 1 . 6 | 7 4 . | . . . |
| 7 . 3 | . . . | . . . |
+-------+-------+-------+
| . . 9 | . 1 . | 5 3 . |
| . 7 . | . . . | 6 . 2 |
| 2 1 . | . 3 . | . 7 . |
+-------+-------+-------+

Now you will now attempt to find a solution to the puzzle

In [7]:
solve(puzzle02)
if solve(puzzle02) is None:
    print("No solution exists for this puzzle.")
else:
    display_puzzle(solve(puzzle02))
+-------+-------+-------+
| 5 6 7 | 1 9 2 | 4 8 3 |
| 9 8 1 | 4 5 3 | 2 6 7 |
| 4 3 2 | 8 7 6 | 1 5 9 |
+-------+-------+-------+
| 8 5 4 | 3 2 1 | 7 9 6 |
| 1 9 6 | 7 4 8 | 3 2 5 |
| 7 2 3 | 5 6 9 | 8 4 1 |
+-------+-------+-------+
| 6 4 9 | 2 1 7 | 5 3 8 |
| 3 7 5 | 9 8 4 | 6 1 2 |
| 2 1 8 | 6 3 5 | 9 7 4 |
+-------+-------+-------+

Puzzle 3

In [8]:
puzzle03 = load_puzzle('puzzle03.txt')

display_puzzle(puzzle03)
Sudoku loaded from puzzle03.txt 

+-------+-------+-------+
| . . 6 | . . 3 | 1 . . |
| 8 . . | . . . | . 3 . |
| . 2 . | . . . | . . 5 |
+-------+-------+-------+
| 5 . . | . 1 . | . . 8 |
| 3 . . | . . . | 2 . . |
| . . 1 | . . 7 | 4 . . |
+-------+-------+-------+
| . 5 . | . 4 6 | 8 . . |
| 4 3 2 | . 7 . | . . . |
| . . . | 5 . . | . . 1 |
+-------+-------+-------+

Now you will now attempt to find a solution to the puzzle

In [9]:
solve(puzzle03)
if solve(puzzle03) is None:
    print("No solution exists for this puzzle.")
else:
    display_puzzle(solve(puzzle03))
+-------+-------+-------+
| 9 4 6 | 8 5 3 | 1 7 2 |
| 8 1 5 | 7 2 9 | 6 3 4 |
| 7 2 3 | 4 6 1 | 9 8 5 |
+-------+-------+-------+
| 5 7 9 | 2 1 4 | 3 6 8 |
| 3 8 4 | 6 9 5 | 2 1 7 |
| 2 6 1 | 3 8 7 | 4 5 9 |
+-------+-------+-------+
| 1 5 7 | 9 4 6 | 8 2 3 |
| 4 3 2 | 1 7 8 | 5 9 6 |
| 6 9 8 | 5 3 2 | 7 4 1 |
+-------+-------+-------+

Puzzle 4

In [10]:
puzzle04 = load_puzzle('puzzle04.txt')

display_puzzle(puzzle04)
Sudoku loaded from puzzle04.txt 

+-------+-------+-------+
| 2 . . | 9 . . | . . . |
| . . . | . . . | . 6 . |
| . . . | . . 1 | . . . |
+-------+-------+-------+
| 5 . 2 | 6 . . | 4 . 7 |
| . . . | . . 4 | 1 . . |
| . . . | . 9 8 | 1 2 3 |
+-------+-------+-------+
| . . . | . . 3 | . 8 . |
| . . 5 | . 1 . | . . . |
| . . 7 | . . . | . . . |
+-------+-------+-------+

Now you will now attempt to find a solution to the puzzle

In [11]:
solve(puzzle04)
if solve(puzzle04) is None:
    print("No solution exists for this puzzle.")
else:
    display_puzzle(solve(puzzle04))
No solution exists for this puzzle.
In [0]: