Guest User

Untitled

a guest
Apr 20th, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. import random
  2. def lagTabell(n):
  3. tabell = []
  4. for i in range(n):
  5. tabell.append([])
  6. for j in range(n):
  7. tabell[i].append(random.randint(0,9))
  8. return tabell
  9.  
  10. def diagPos(tabell):
  11. newTab = []
  12. for i in range(len(tabell)):
  13. for j in range(i,i+1):
  14. if tabell[i][j] > 0:
  15. newTab.append(tabell[i][j])
  16. return newTab
  17.  
  18. def sqmod(n):
  19. ut = n - ((n-1)%3)
  20. return ut
  21.  
  22. def validate_square(tabell, N):
  23. for i in range(len(tabell)):
  24. for j in range(len(tabell[i])):
  25. if tabell[i][j] == N: return False
  26. elif tabell[i][j] == 0: return True
  27.  
  28. def validate_row(liste,N):
  29. for i in range(len(liste)):
  30. if liste[i] == N:
  31. return False
  32. elif liste[i] == 0: return True
  33.  
  34.  
  35. def valid_insertion(brett,row,col,N):
  36. isValid = True
  37. if validate_row(brett[row-1],N) == False: return False
  38.  
  39. aRow = sqmod(row)
  40. aCol = sqmod(col)
  41.  
  42. square = []
  43. k = 0
  44. for i in range(aRow-1,aRow+2):
  45. square.append([])
  46. k = 0
  47. for j in range(aCol-1,aRow+2):
  48. square[k].append(brett[i][j])
  49. k+=1
  50. isValid = validate_square(square,N)
  51. return isValid
  52.  
  53. brett = lagTabell(9)
  54. for i in brett:
  55. print i
  56. print valid_insertion(brett,9,9,3)
Add Comment
Please, Sign In to add comment