2 Replies - 375 Views - Last Post: 02 February 2012 - 08:40 PM Rate Topic: -----

Topic Sponsor:

#1 UrIkOn  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 40
  • Joined: 06-November 11

Sudoku Problem

Posted 02 February 2012 - 07:50 PM

I am studying the implementation code for the sudoku.
We must check the validity of sudoku by column,row and 3*3 box.
I din't understand the explanation of code given by the book.
//check whether grid[i][j] is valid in the 3-by-3 box
bool isValid(int i,int j,const int grid[][9])
{  for(int row=(i/3)*3;row<(i/3)*3+3;row++)
   {
           for(int col=(j/3)*3;col<(j/3)*3+3;col++)
           { if(row !=i && col !=j && grid[row][col]==grid[i][j])
             { return false; }
           }
   }
   return false;
}

The explanation is :
For any grid[i][j] in the 3-by-3 box,its starting cell is grid[3*(i/3)][3*(j/3)](i.e.grid[0][6]).
For example,for grid[2][8],i=2,j=8,3*(j/3)=0 and 3*(j/3)=6.
I don't understand this part.
Anyone can spend some time help me explain on this?

Is This A Good Question/Topic? 0
  • +

Replies To: Sudoku Problem

#2 r.stiltskin  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1812
  • View blog
  • Posts: 4,891
  • Joined: 27-December 05

Re: Sudoku Problem

Posted 02 February 2012 - 07:57 PM

In integer division, fractions are discarded. So, for example look at the division of 8/3. Mathematically, the result is 2 2/3, but since these are integers we discard the 2/3 and now the result is just 2.
Was This Post Helpful? 0
  • +
  • -

#3 UrIkOn  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 40
  • Joined: 06-November 11

Re: Sudoku Problem

Posted 02 February 2012 - 08:40 PM

Oh..I forget this rule already.
Thank you for your answering!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1