Guest User

Untitled

a guest
Apr 20th, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.10 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(3,3))
  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:
  26.                 return False
  27.     return True
  28.  
  29. def validate_row(liste,N):
  30.     for i in range(len(liste)):
  31.         if liste[i] == N:
  32.             return False
  33.         return True
  34.  
  35.  
  36. def valid_insertion(brett,row,col,N):
  37.     isValid = True
  38.     if validate_row(brett[row-1],N) == False: return False
  39.    
  40.     aRow = sqmod(row)
  41.     aCol = sqmod(col)
  42.    
  43.     square = []
  44.     k = 0
  45.     for i in range(aRow-1,aRow+2):
  46.         square.append([])
  47.         k = 0
  48.         for j in range(aCol-1,aRow+2):
  49.             square[k].append(brett[i][j])
  50.         k+=1
  51.     isValid = validate_square(square,N)
  52.     return isValid
  53.  
  54. brett = lagTabell(9)
  55. for i in brett:
  56.     print i
  57. print valid_insertion(brett,9,9,3)
Add Comment
Please, Sign In to add comment