absfuyu.game.sudoku module

Game: Sudoku

Sudoku 9x9 Solver

Version: 5.1.0 Date updated: 10/03/2025 (dd/mm/yyyy)

Credit:

class absfuyu.game.sudoku.Sudoku(sudoku_data: list[list[int]])[source]

Bases: object

export_to_string(*, style: Literal['dot', 'zero'] = 'dot') str[source]

Export Sudoku data to string form

Parameters:

style (Literal["dot", "zero"]) –

  • “zero”: 0 is 0

  • ”dot”: 0 is .

Returns:

Sudoku string

Return type:

str

classmethod from_string(string_data: str)[source]

Convert sudoku string format into list

Parameters:

string_data (str) – String data

Returns:

Sudoku instance

Return type:

Sudoku

Example:

>>> Sudoku.from_string("8..........36......7..9.2...5...7.......457.....1...3...1....68..85...1..9....4..")
[[8, 0, 0, 0, 0, 0, 0, 0, 0],
 [0, 0, 3, 6, 0, 0, 0, 0, 0],
 [0, 7, 0, 0, 9, 0, 2, 0, 0],
 [0, 5, 0, 0, 0, 7, 0, 0, 0],
 [0, 0, 0, 0, 4, 5, 7, 0, 0],
 [0, 0, 0, 1, 0, 0, 0, 3, 0],
 [0, 0, 1, 0, 0, 0, 0, 6, 8],
 [0, 0, 8, 5, 0, 0, 0, 1, 0],
 [0, 9, 0, 0, 0, 0, 4, 0, 0]]
classmethod hardest_sudoku()[source]

Create Hardest Sudoku instance ([Source](https://www.telegraph.co.uk/news/science/science-news/9359579/Worlds-hardest-sudoku-can-you-crack-it.html))

Returns:

Sudoku instance

Return type:

Sudoku

to_board_form() str[source]

Prepare sudoku board ready to print

Returns:

Sudoku Board data that ready to print

Return type:

str

Example:

>>> demo = Sudoku.hardest_sudoku()
>>> print(demo.to_board_form())
┎─────────────────────────────┒
┃  8 0 0  ┃  0 0 0  ┃  0 0 0  ┃
┃  0 0 3  ┃  6 0 0  ┃  0 0 0  ┃
┃  0 7 0  ┃  0 9 0  ┃  2 0 0  ┃
┠─────────────────────────────┨
┃  0 5 0  ┃  0 0 7  ┃  0 0 0  ┃
┃  0 0 0  ┃  0 4 5  ┃  7 0 0  ┃
┃  0 0 0  ┃  1 0 0  ┃  0 3 0  ┃
┠─────────────────────────────┨
┃  0 0 1  ┃  0 0 0  ┃  0 6 8  ┃
┃  0 0 8  ┃  5 0 0  ┃  0 1 0  ┃
┃  0 9 0  ┃  0 0 0  ┃  4 0 0  ┃
┖─────────────────────────────┚
solve()[source]

Solve the Sudoku

Returns:

Sudoku instance

Return type:

Sudoku

Example:

>>> test = Sudoku.hardest_sudoku()
>>> test.solve()
>>> print(test.to_board_form())
 ┎─────────────────────────────┒
 ┃  8 1 2  ┃  7 5 3  ┃  6 4 9  ┃
 ┃  9 4 3  ┃  6 8 2  ┃  1 7 5  ┃
 ┃  6 7 5  ┃  4 9 1  ┃  2 8 3  ┃
 ┠─────────────────────────────┨
 ┃  1 5 4  ┃  2 3 7  ┃  8 9 6  ┃
 ┃  3 6 9  ┃  8 4 5  ┃  7 2 1  ┃
 ┃  2 8 7  ┃  1 6 9  ┃  5 3 4  ┃
 ┠─────────────────────────────┨
 ┃  5 2 1  ┃  9 7 4  ┃  3 6 8  ┃
 ┃  4 3 8  ┃  5 2 6  ┃  9 1 7  ┃
 ┃  7 9 6  ┃  3 1 8  ┃  4 5 2  ┃
 ┖─────────────────────────────┚