I need to generate a matrix 7*7 and with the following rules:
- The first and last row and column must contain a set of numbers that add up to a total of 6. And only the numbers 0, 1, 2 can be used randomly.
- The other Columns and rows add up (each) to 12 using numbers 0 1 2 3 4 randomly.
There are additional conditions but the ultimate goal is to generate a matrix of numbers similar to this:
I have tried to use a code such as this one:(this is just for the first row)
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main()
{
int i, j, x;
int grille[7][7];
int limV[7], limH[7], copy[7];
srand ((unsigned) time (NULL));
x=0;
for(i=0; i<7; i++){
limV[i]= 0;
limH[i]= 0;
}
while(limH[0]!=6){
limH[0]=0;
for(i=0; i<7; i++){
if(i==0 || i==6){
grille[0][i] = rand()%2;
limH[0] += grille[0][i];
limV[i] = grille[0][i] ;
} else{
grille[0][i] = rand()%3;
limH[0] += grille[0][i];
limV[i] = grille[0][i] ;
}
}
}
return 0;
}
I am not looking for the solution to this algorithm but rather a hint or tips to be able to move forward in my project.
