Beispiel #1
0
def randomFill(puzzle):
	locs = Sudoku.checkFilled(puzzle)[1]

	while not Sudoku.checkCorrect(puzzle)[0]:
		for i in locs:
			puzzle[i[0]][i[1]] = random.randint(1, len(puzzle))

	return puzzle
Beispiel #2
0
def bruteForce(puzzle):
	if Sudoku.checkFilled(puzzle)[0]:
		print 'Filled a puzzle'
		if Sudoku.checkCorrect(puzzle)[0]:
			return puzzle
	else:
		spot = Sudoku.checkFilled(puzzle)[1][0]
		for num in range(1, len(puzzle) + 1):
			# Check that the number can go here
			valid = True
			for i in range(len(puzzle)):
				if puzzle[spot[0]][i] == num or puzzle[i][spot[1]] == num:
					valid = False

			if valid:
				puzzle[spot[0]][spot[1]] = num
				ret = bruteForce(puzzle)
				if ret:
					return ret

		puzzle[spot[0]][spot[1]] = 0