-
-
Save zokis/333b27da80695116aa3b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def valida_q_magico(q_magico): | |
if len(q_magico) == 0 or len(q_magico) != len(q_magico[0]): | |
return False | |
linhas_ok = not sum( | |
1 if sum(linha) != sum(q_magico[0]) else 0 | |
for linha in q_magico | |
) | |
colunas_ok = not sum( | |
sum( | |
linha[i] for linha in q_magico | |
) != sum(q_magico[0]) | |
for i in range(len(q_magico[0])) | |
) | |
diagonais_ok = True | |
for i in range(len(q_magico[0])): | |
if sum( | |
linha[i] for linha in q_magico | |
) != sum(q_magico[0]): | |
diagonais_ok = False | |
i += 1 | |
return linhas_ok and colunas_ok and diagonais_ok | |
q_magico = [ [2, 7, 6], [9, 5, 1], [4, 3, 8] ] | |
print q_magico, valida_q_magico(q_magico) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment