Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
An Array Challenge
bool cuadrante(char v,ulong n,ulong m,ulong n2,ulong m2, char [][] grid){
ulong i,j;
ulong lim,lim2;
lim = 3 * (n+1);
lim2 = 3 * (m+1);
bool bandera = true;
for (i=3*n;i<lim;i++){
for(j=3*m;j<lim2;j++){
if(i != n2 || j!=m2){
if(v == grid[i][j] ){
bandera = false;
}
}
}
}
return bandera;
}
bool findCoincidences(char[][] grid,ulong n ,ulong m){
char valor = grid[n][m];
ulong i,j,k;
for (i = 0; i<= 8; i++){
if(!(i==m)){
if(grid[n][i]==valor){
return false;
}
}
}
for (i = 0; i<= 8; i++){
if(!(i==n)){
if(grid[i][m]==valor){
return false;
}
}
}
// buscar en cuadrante
j = n/3;
k = m/3;
bool buscar = cuadrante(valor,j,k,n,m,grid);
if(!buscar){
return false;
}
return true;
}
bool sudoku2(char[][] grid) {
foreach(i,e; grid){
foreach(j,v;e){
if(!(v == '.')){
bool valido = findCoincidences(grid,i,j);
if (!valido){
return false;
}
}
}
}
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.