Skip to content

Instantly share code, notes, and snippets.

@danoneata
Created June 14, 2017 09:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danoneata/dfe9f50f50c62b9127b4f008e22e5259 to your computer and use it in GitHub Desktop.
Save danoneata/dfe9f50f50c62b9127b4f008e22e5259 to your computer and use it in GitHub Desktop.
Skeleton code for Sudoku solver in Python
from typing import (
List,
TypeVar,
)
# Type aliases
A = TypeVar('A')
Digit = int
Matrix = List[List[A]]
Grid = Matrix[Digit]
# Some grids
grid1 = [[0, 2, 4, 0],
[1, 0, 0, 3],
[4, 0, 0, 2],
[0, 1, 3, 0]] # type: Grid
grid2 = [[0, 3, 0, 1],
[1, 0, 3, 2],
[3, 0, 1, 0],
[0, 1, 0, 3]] # type: Grid
# Define grid size
box_size = 2
grid_size = box_size * box_size
# Exercise 1
def solve(grid: Grid) -> List[Grid]:
pass
# Exercise 2
def completions(grid: Grid) -> List[Grid]:
pass
# Exercise 3
def choices(grid: Grid) -> Matrix[List[Digit]]:
pass
# Exercise 4
def expand(matrix: Matrix[List[Digit]]) -> List[Grid]:
pass
# Exercise 5
def cp(xss: List[List[A]]) -> List[List[A]]:
pass
# Exercise 6
def valid(grid: Grid) -> bool:
pass
# Exercise 7
def nodups(xs: List[A]) -> bool:
pass
# Exercise 8
def rows(grid: Matrix[A]) -> Matrix[A]:
pass
# Exercise 9
def cols(grid: Matrix[A]) -> Matrix[A]:
pass
# Exercise 10
def boxs(grid: Matrix[A]) -> Matrix[A]:
pass
# Exercise 11
def group(xs: List[A]) -> List[List[A]]:
pass
# Exercise 12
def ungroup(xss: List[List[A]]) -> List[A]:
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment