Number the coins 1 through 12. Weigh coins 1, 2, 3, 4 against coins 5, 6, 7, 8. If they balance, weigh coins 9 and 10 against coins 11 and 8 (we know from the first weighing that 8 is a good coin). If they balance, we know coin 12, the only coin not weighed is the counterfeit one. The third weighing indicates whether it is heavy or light.
If, however, at the second weighing, coins 11 and 8 are heavier than coins 9 and 10, either 11 is heavy or 9 is light or 10 is light. Weight 9 with 10. If they balance, 11 is heavy. If they don't balance, either 9 or 10 is light.
Now assume that at first weighing the side with coins 5, 6, 7, 8 is heavier than the side with coins 1, 2, 3, 4. This means that either 1, 2, 3, 4 is light or 5, 6, 7, 8 is heavy. Weigh 1,2, and 5 against 3,6, and 9. If they balance, it means that either 7 or 8 is heavy or 4 is light. By weighing 7 and 8 we obtain the answer, because if they balance, then 4 has to be light. If 7 and 8 do not balance, then the heavier coin is the counterfeit.
If when we weigh 1, 2, and 5 against 3,6 and 9, the right side is heavier, then either 6 is heavy or 1 is light or 2 is light. By weighing 1 against 2 the solution is obtained.
If however, when we weigh 1, 2, and 5 against 3, 6 and 9, the right side is lighter, then either 3 is light or 5 is heavy. By weighing 3 against a good coin the solution is easily arrived at.