Microsoft Interview Question
Software Engineer in TestsA lil more python-like. Wot say?
from itertools import product
def suggest(board, i, j):
gridX, gridY = (int(i / 3) * 3, int(j / 3) * 3)
suggestions = set(range(1, 10)) - set(board[i]) - set([board[x][j] for x in range(0, 9)])
suggestions -= set([board[gridX + x][gridY + y] for (x, y) in product(range(0,3), range(0, 3))])
return list(suggestions)
nice code.
In short, what he is trying to do is:
1. Check the entire ith row and jth column and eliminate the possibilities of a number if it appears in these.
2. Repeat the same for the 3*3 square that (i,j) is part of nice.
Thanks.
Not all Sudoku is 9*9 large. Some easy ones are 2*3 and some difficult ones are 4*4.
Use two extra args to fit into more general cases.
(C# code)
public List<int> SudokuHint(int[,] board, Point p, int row, int col)
sample python code, language doesn't matter...
- Anonymous February 01, 2010