sudoku solver
No output coming in sudoko solver
Hello @vinaykumar4530,
//Why are you doing square root when it is mentioned in the question that N is a multiple of 3.
int sx = (r / sqrt(n)) * sqrt(n); //It will result into r only. There is need of multiplication
int sy = (c / sqrt(n)) * sqrt(n); //Similarly, It will result into c only.
for (int i = sx; i < sx + sqrt(n); ++i) {
for (int j = sy; j < sy + sqrt(n); ++j) {
if (arr[i][j] == number) {
return false;
}
}
}
This part of your code is causing run time error as the loop is iterating for the values greater than n.
//columns are till n-1
if (cc == n-1) {
sudoko_solver(arr, cr + 1, 0, n);
}
Hope, this would help.
Give, a like if you are satisfied.
int sx = (r / sqrt(n)) * sqrt(n);
no it will not result in r only as (r / sqrt(n)) this part is computing first
and second if cc goes out of bound than only we will will increment cr because for cc==n-1 we will check by putting values
Can you explain your logic behind computing square root?
When i am running this code for different values of no it is returning no. So, how is it different from what you have written. Please, clear.
#include <bits/stdc++.h>
using namespace std;
int main() {
int no;
cin>>no;
int a =(5/sqrt(9))*sqrt(9);
cout<<a;
return 0;
}
i am finding out the starting dimensions of the sub matrix of sudoku to check
i have modified my code but now infinite output coming
Hello @vinaykumar4530,
I have modified your code.
Now, it is passing all testcases.
You can check it here.
Hope, this would help.
Give a like, if you are satisfied.