Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- def lagTabell(n):
- tabell = []
- for i in range(n):
- tabell.append([])
- for j in range(n):
- tabell[i].append(random.randint(3,3))
- return tabell
- def diagPos(tabell):
- newTab = []
- for i in range(len(tabell)):
- for j in range(i,i+1):
- if tabell[i][j] > 0:
- newTab.append(tabell[i][j])
- return newTab
- def sqmod(n):
- ut = n - ((n-1)%3)
- return ut
- def validate_square(tabell, N):
- for i in range(len(tabell)):
- for j in range(len(tabell[i])):
- if tabell[i][j] == N:
- return False
- return True
- def validate_row(liste,N):
- for i in range(len(liste)):
- if liste[i] == N:
- return False
- return True
- def valid_insertion(brett,row,col,N):
- isValid = True
- if validate_row(brett[row-1],N) == False: return False
- aRow = sqmod(row)
- aCol = sqmod(col)
- square = []
- k = 0
- for i in range(aRow-1,aRow+2):
- square.append([])
- k = 0
- for j in range(aCol-1,aRow+2):
- square[k].append(brett[i][j])
- k+=1
- isValid = validate_square(square,N)
- return isValid
- brett = lagTabell(9)
- for i in brett:
- print i
- print valid_insertion(brett,9,9,3)
Add Comment
Please, Sign In to add comment