To solve this problem, let's denote the following:
- Let \( A \) be the set of candidates who passed chemistry.
- Let \( B \) be the set of candidates who passed physics.
- The number of candidates who passed chemistry \( |A| = 31 \).
- The number of candidates who passed physics \( |B| = 29 \).
- The number of candidates who failed both subjects is 3.
- Therefore, the total number of candidates who sat for the examination is 50.
From this, we can find the total number of candidates who passed at least one of the subjects:
\[ \text{Candidates passed at least one subject} = \text{Total candidates} - \text{Failed both} \] \[ = 50 - 3 = 47 \]
Using the principle of inclusion-exclusion for the sets \( A \) and \( B \):
\[ |A \cup B| = |A| + |B| - |A \cap B| \]
Where \( |A \cup B| \) is the total number of candidates who passed at least one subject (which we found to be 47). Thus, we write:
\[ 47 = 31 + 29 - |A \cap B| \]
Now, simplifying this expression:
\[ 47 = 60 - |A \cap B| \]
So, we can solve for \( |A \cap B| \):
\[ |A \cap B| = 60 - 47 = 13 \]
Now we have:
- \( |A| = 31 \) (candidates passed chemistry)
- \( |B| = 29 \) (candidates passed physics)
- \( |A \cap B| = 13 \) (candidates who passed both subjects)
To find the number of candidates who passed chemistry only, we use the formula:
\[ |A \text{ only}| = |A| - |A \cap B| \] \[ |A \text{ only}| = 31 - 13 = 18 \]
Thus, the number of candidates who passed chemistry only is \( \boxed{18} \).