This is a very old question. I remember being asked this question about 25 years ago.
The answer is to divide to three groups, as equal as possible. You have 9 coins. You start by measuring 3 against 3. If one is lighter than the other, that's where the coin is, and you again split to 3 piles of one coin each and measure. If both are the same, the counterfeit coin is the one left out - meaning you only need two weightings to find the counterfeit.
We're a place where coders share, stay up-to-date and grow their careers.
We strive for transparency and don't collect excess data.