Guest User

Untitled

a guest
Apr 20th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.18 KB | None | 0 0
  1. def validateSquare(tabell,tall):
  2.     for i in range(len(tabell)):
  3.         for j in range(len(tabell[0])): #Antar like mange kolonner i hver rad, eventuelt tabell[i] i andre oppgaver
  4.             if tall == tabell[i][j]: return False
  5.     return True
  6. #3b#
  7. def validatePosition(tabell,rad,kolonne):
  8.     if not tabell[rad][kolonne]: return True
  9.     else: return False
  10.  
  11. def validateRowCol(liste,tall):
  12.     for i in range(len(liste)):
  13.         if tall == liste[i]:
  14.             if tall != 0: return False
  15.     return True
  16.  
  17. def validateInsertion(tabell,rad,kolonne,tall):
  18.     kvadrat = [[0 for i in range(3)]for j in range(3)]
  19.     modrad = rad%3 #Brukes for aa sjekke hvilken del man er i den lille firkanten
  20.     modkol = kolonne%3 #Samme
  21.     for i in range((rad-modrad),((rad/3)+1)*3):
  22.         for j in range((kolonne-modkol),((kolonne/3)+1)*3):
  23.             kvadrat[i-rad][j-kolonne] = tabell[i][j]
  24.     radsjekk = []
  25.     for i in range(len(tabell)):
  26.         radsjekk.append(tabell[i][kolonne])
  27.     if (validateSquare(kvadrat,tall) and validatePosition(tabell,rad,kolonne) and
  28.         validateRowCol(tabell[rad],tall) and validateRowCol(radsjekk,tall)): return True
  29.     else: return False
Add Comment
Please, Sign In to add comment