TITLE: Mathematical reasoning question
QUESTION [7 upvotes]: I was giving a look at my country's mathematical olympiads, and I found this problem

If I want to color a $4\times 4$ grid with black and white squares, in how many ways
      can I paint it such that every row and every column has 2 squares of each color?

After thinking for a while, I decided to code a program that gave me insights about the problem by reverse-engeneering the answer.No success.Aparently, the answer is $90$, but how does the mathematical way of doing this goes?

REPLY [2 votes]: This explanation is a little more wordy, but hopefully will help you with the kind of intuition you need to solve similar problems.
So there are ${{4}\choose{2}} = 6$ ways to choose the 2 black squares in the first row. Once we have chosen those two squares we know there are two columns where we must pick exactly one more black square. For example, if we choose columns 2 and 3 for row one, then we must pick 1 more black in column 2 (in either row 2, 3, or 4), and 1 for column 3. There are ${{3}\choose{1}} = 3$ ways to do this for each column, so $3^2 = 9$ ways in total for both columns.
Now, suppose we picked both choices to be on the same row, then there would be two empty rows of which we only have one possible choice for the remaining 4 blacks. For example, using notation (row,column), say we first picked (1,2) and (1,4), and then (3,2) and (3,4), then we have (2,1), (2,3), (4,1), and (4,4) left as possible choices for our 4 remaining blacks, giving ${{4}\choose{4}} = 1$ as stated. If our choices are not on the same row then there are 2 possible choices for the 4 remaining blacks as we can choose which column to put the first remaining black out of the 2 remaining columns. For example, if we first picked (1,2) and (1,4), and then (2,2) and (3,4), it is now easy to see there are only 2 sets of remaining positions that satisfy the requirements, i.e. {(2,1),(3,3),(4,1),(4,3)} and (2,3),(3,1),(4,1),(4,3)}.
There are 6 ways for the second 2 blacks to be arranged in the 2 columns such that the don't fall onto the same row. And as each of these has an additional way of arranging the 4 remaining blacks, we have a total of $9 + 6 = 15$ ways to choose the remaining 6 blacks once we choose the first 2. Thus in total we have $6 \times 15 = 90$ ways to arrange the blacks.