correction poetit bug dans fonction solve_one et ajout main5.py
This commit is contained in:
parent
3b3a960a2a
commit
e0c3657074
62
Solver/main5.py
Executable file
62
Solver/main5.py
Executable file
@ -0,0 +1,62 @@
|
||||
#!/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)
|
||||
|
@ -152,6 +152,7 @@ def solve_one(grid, pause=0):
|
||||
res = solve_one(grid, pause)
|
||||
if not res is None:
|
||||
return res
|
||||
grid[i, j] = EMPTY_SYMBOL
|
||||
return res
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user