Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def check_matrix(m):
- pass
- def get_range_for_cell(m,x,y):
- r = [1,2,3,4,5]
- for j in range(size):
- try:
- i = r.index(m[y][j])
- except ValueError: pass
- else: del r[i]
- try:
- i = r.index(m[j][x])
- except ValueError: pass
- else: del r[i]
- #print(len(r))
- return r
- def solve(m):
- d = []
- modified = 0
- while (True):
- for y in range(size):
- for x in range(size):
- if (m[y][x] == 0):
- rng = get_range_for_cell(m,x,y) # searching possible variants for cell
- if len(rng) == 1:
- m[y][x] = rng[0] # just one variant - put it
- modified += 1
- else:
- d.append({'x':x, 'y':y, 'range':rng, 'pos':0 }) # put variants and set pointer to zero
- if (modified == 0):
- break
- modified = 0
- print(m)
- matrix = [
- [5,1,0,2,0],
- [0,0,0,5,1],
- [4,5,1,0,0],
- [0,0,0,4,5],
- [0,4,5,0,3]]
- size = len(matrix)
- solve(matrix)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement