63 lines
1.6 KiB
Python
Executable File
63 lines
1.6 KiB
Python
Executable File
#!/usr/bin/python3
|
|
# -*- coding: utf-8 -*-
|
|
|
|
"""
|
|
:mod: module
|
|
:author: `Éric W`
|
|
:date: 2016, october
|
|
|
|
"""
|
|
|
|
GRID='''
|
|
+-------+-------+-------+
|
|
| 9 . 6 | . 2 8 | . . 3 |
|
|
| . 4 . | 5 . . | . . 1 |
|
|
| . 8 . | 9 . . | . 4 . |
|
|
+-------+-------+-------+
|
|
| 6 . . | . . . | . 7 . |
|
|
| . . 8 | 2 . 6 | 9 . . |
|
|
| . 3 . | . . . | . . 5 |
|
|
+-------+-------+-------+
|
|
| . 5 . | . . 3 | . 6 . |
|
|
| 1 . . | . . 2 | . 8 . |
|
|
| 2 . . | 8 7 . | 5 . . |
|
|
+-------+-------+-------+
|
|
'''
|
|
|
|
def usage():
|
|
print('Usage: {:s} <grid> <pause>'.format(sys.argv[0]))
|
|
print('where\n\t<grid> is a 81 characters string describing a valid sudoku grid')
|
|
print('\t<pause> is the pause between two tentatives')
|
|
print('\nExample: with the grid')
|
|
print(GRID)
|
|
print('and a pause of 0.5 second')
|
|
print('$ {:s} 906028003040500001080900040600000070008206900030000005050003060100002080200870500 0.5'.format(sys.argv[0]))
|
|
exit(1)
|
|
|
|
if __name__ == '__main__':
|
|
import sys, time
|
|
import sudoku_grid, sudoku_solver
|
|
|
|
|
|
if len(sys.argv) != 3:
|
|
usage()
|
|
else:
|
|
strgrid = sys.argv[1]
|
|
try:
|
|
grid = sudoku_grid.SudokuGrid(strgrid)
|
|
except sudoku_grid.SudokuGridError:
|
|
print('grid description is not valid')
|
|
usage()
|
|
try:
|
|
pause = float(sys.argv[2])
|
|
except ValueError:
|
|
print('pause argument is not valid')
|
|
usage()
|
|
print('Sudoku to solve')
|
|
grid.pretty_print()
|
|
_ = input('Tapez entrée pour continuer')
|
|
sols = sudoku_solver.solve_one(grid, pause)
|
|
|
|
exit(0)
|
|
|