I have a question for you guys. My Bro is working on this for a project and this problem came up. I want to surprise him with the answer. I figured if anyone could deal with it, you guys could. I had to copy and paste it and I am not much of a programmer so if there are any mistakes, I apologize. Any ideas or insight would be great. Thanks in advance! Ark
"I have generated a 10x10 integer matrix, by way of a 2 dimensional array, the elements are randomly generated and lie on
1 <= z <= 5
I am in need of an efficient method of setting all adjacent "duplicates" (repeating elements), along any row or column (not diagonally), of length 3 or greater to the integer six (6). The source for the brute method follows for clarity.
for(row=0;row<10;row++)
{
for(col=0;col<10;col++)
{
board[row][col]=rand()%4+1; //filling matrix here
}
}
print_board(board, row, col);
printf("Switch: ROW COLUMN\n ");
scanf("%hu %hu", &x1, &y1);
printf("With: ROW COLUMN\n");
scanf("%hu %hu", &x2, &y2);
swap(board, x1, y1,x2, y2); //stdrd for loop no good b/c of
//below <-this->below
if(board[0][0]==board[0][1] && board[0][1]==board[0][2] && board[0][2]==board[0][3])
{
board[0][0]=6;
board[0][1]=6;
board[0][2]=6;
board[0][3]=6; // brute force would require many more to complete
}
I know there must exist a much more elegant approach than listing out all permutations. If you have seen this and recall the technique I would very much appreciate your assistance."