Function Repository Resource:

GenerateKillerSudokuPuzzle

Source Notebook

Generate a killer sudoku puzzle

Contributed by: Paritosh Mokhasi

ResourceFunction["GenerateKillerSudokuPuzzle"][]

generates a 9×9 killer sudoku puzzle and provides the regular sudoku puzzle used to generate it.

Details and Options

The first element returned by the function is the reference sudoku puzzle.
The second element returned by the function is a two element List {pos,vals}:
The first element is a list of lists containing the matrix positions of the cage.
The second element is a list of positive integers and represents the sum of all the numbers in that cage.
The objective is to use the cage information to find all the elements of the board such that the final solved puzzle must obey the three rules of a standard sudoku board.
The three rules of a standard sudoku board are:
First, each row must contain all the numbers 1–9.
Second, each column must contain all the numbers 1–9.
Third, each 3×3 block must contain all the numbers 1–9.

Examples

Basic Examples (4) 

Generate a killer sudoku puzzle:

In[1]:=
SeedRandom[123];
Short[{refSudokuPuzzle, {cagePos, cageVals}} = ResourceFunction["GenerateKillerSudokuPuzzle"][], 3]
Out[2]=

Display the killer sudoku puzzle with the resource function DisplayKillerSudokuPuzzle:

In[3]:=
ResourceFunction["DisplayKillerSudokuPuzzle"][cagePos, cageVals]
Out[3]=

Solve the killer sudoku puzzle:

In[4]:=
solvedPuzzle = ResourceFunction["SolveKillerSudokuPuzzle"][cagePos, cageVals]
Out[4]=

Display the solved sudoku puzzle using the resource function DisplaySudokuPuzzle:

In[5]:=
ResourceFunction["DisplaySudokuPuzzle"][solvedPuzzle]
Out[5]=

Publisher

Paritosh Mokhasi

Version History

  • 1.0.0 – 20 May 2020

Related Resources

License Information