Advertisement
Guest User

Untitled

a guest
Jun 2nd, 2015
286
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. rows = {}
  2. columns = {}
  3. squares = {}
  4. ok = True
  5. print('\n')
  6. for i in range(0,9):
  7. r = raw_input();
  8. while r == '':
  9. r = raw_input();
  10. values = map(int, filter(lambda x: x != '', r.split(' ')))
  11. for j in range(0,9):
  12. k = values[j]
  13. n = str(i) + "-" + str(k)
  14. if n in rows.keys():
  15. ok = False
  16. print("row %i already has value %i at column %i" % (i, k, rows[n]))
  17. else:
  18. rows[n] = j
  19. n = str(j) + "-" + str(k)
  20. if n in columns.keys():
  21. ok = False
  22. print("column %i already has value %i at row %i" % (j, k, columns[n]))
  23. else:
  24. columns[n] = i
  25. n = str(i // 3) + "-" + str(j // 3) + "-" + str(k)
  26. if n in squares.keys():
  27. ok = False
  28. print("square %i-%i already has value %i at position %s" % (i // 3, j // 3, k, squares[n]))
  29. else:
  30. squares[n] = str(i) + "-" + str(j)
  31.  
  32. if ok:
  33. print("Sudoku checked")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement