forked from RutledgePaulV/sudoku-generator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsudoku_generator.py
41 lines (30 loc) · 1.13 KB
/
sudoku_generator.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# !/usr/bin/python
import sys
from Sudoku.Generator import *
# setting difficulties and their cutoffs for each solve method
difficulties = {
'easy': (35, 0),
'medium': (81, 5),
'hard': (81, 10),
'extreme': (81, 15)
}
# getting desired difficulty from command line
difficulty = difficulties[sys.argv[2]]
# constructing generator object from puzzle file (space delimited columns, line delimited rows)
gen = Generator(sys.argv[1])
# applying 100 random transformations to puzzle
gen.randomize(100)
# getting a copy before slots are removed
initial = gen.board.copy()
# applying logical reduction with corresponding difficulty cutoff
gen.reduce_via_logical(difficulty[0])
# catching zero case
if difficulty[1] != 0:
# applying random reduction with corresponding difficulty cutoff
gen.reduce_via_random(difficulty[1])
# getting copy after reductions are completed
final = gen.board.copy()
# printing out complete board (solution)
print("The initial board before removals was: \r\n\r\n{0}".format(initial))
# printing out board after reduction
print("The generated board after removals was: \r\n\r\n{0}".format(final))