Last active
December 17, 2015 15:19
-
-
Save arthurxavierx/5630768 to your computer and use it in GitHub Desktop.
Sudoku verifier
This file contains 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
/** | |
* sudoku.c | |
* @author Arthur Xavier <arthur.xavierx@gmail.com> | |
*/ | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <stdbool.h> | |
int main() { | |
size_t i, j; | |
ushort linhas, colunas, quadrados; | |
ushort sudoku[9][9]; | |
bool valido = true; | |
for(i = 0; i < 9; i++) | |
for(j = 0; j < 9; j++) | |
scanf("%hu", sudoku[i] + j); | |
for(i = 0; i < 9; i++) { | |
for(j = 0, linhas = 0, colunas = 0, quadrados = 0; j < 9; j++) { | |
linhas |= 1 << (sudoku[i][j] - 1); | |
colunas |= 1 << (sudoku[j][i] - 1); | |
quadrados |= 1 << (sudoku[(i/3)*3 + j/3][(i%3)*3 + j%3] - 1); | |
} | |
valido &= (linhas == 511) && (colunas == 511) && (quadrados == 511); | |
} | |
printf(valido ? "Solucao atende as regras!\n" : "Solucao nao atende as regras!\n"); | |
return 0; | |
} |
This file contains 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
5 3 4 6 7 8 9 1 2 | |
6 7 2 1 9 5 3 4 8 | |
1 9 8 3 4 2 5 6 7 | |
8 5 9 7 6 1 4 2 3 | |
4 2 6 8 5 3 7 9 1 | |
7 1 3 9 2 4 8 5 6 | |
9 6 1 5 3 7 2 8 4 | |
2 8 7 4 1 9 6 3 5 | |
3 4 5 2 8 6 1 7 9 |
This file contains 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
4 6 5 9 2 3 8 1 7 | |
7 3 8 4 1 5 6 9 2 | |
2 9 1 7 6 8 3 4 5 | |
5 7 6 3 9 1 4 2 8 | |
8 4 9 5 7 2 1 3 6 | |
1 2 3 8 4 6 5 7 9 | |
3 8 7 1 5 9 2 6 4 | |
9 5 2 6 3 4 7 8 1 | |
6 1 4 2 8 7 9 5 3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment