<p>dwharris has the right idea. I also did this problem a long time ago, but it took me a while to remember the solution. I hope this explanation works. (It would be better if I displayed it in a tree structure I guess, but Ill try paragraph form.)</p>
<p>Number the coins 1-12. Divide coins into 3 groups: 1-4 are group A, 5-8 are B, and 9-12 are C. The first weighing is group A vs. group B.</p>
<p>The easy case is when A=B, and you know the coin is in group C. For the 2nd weighing, weigh 2 coins in group C against each other, for example 9 vs. 10. If those are equal, you know it is either 11 or 12 that is the different one. For the last weighing, do 9 vs. 11. If equal, #12 is the answer. If not equal, its #11. If however, 9 vs. 10 was NOT equal, say 9 < 10, then it is either #9 and its lighter or #10 and its heavier. So for the last weighing do 9 vs. 11. If equal, then the answer is #10. If 9 < 11 then its #9 (Note that its not possible for you to get 9 > 11).</p>
<p>So that branch covered the solution being in group C. Now back to the original weighing of A vs. B, suppose its not equal and without loss of generality lets say A < B. Now we know the coin is either in group A and light or group B and heavy. For the 2nd weighing, put coins 1, 2, and 5 on the left and 4, 6, and 9 on the right (other configurations with this pattern work as well, but Im going to use those numbers).</p>
<p>If (1, 2, 5) = (4, 6, 9), then those coins are all ok, leaving the possibilities that 3 is light or that either 7 or 8 is heavy. So for the last weighing, do 7 vs. 8. If equal, #3 is the light coin. If 7 < 8, #8 is heavy. If 7 > 8, then #7 is heavy. </p>
<p>If (1, 2, 5) < (4, 6, 9), then the possibilities are that either 1 or 2 is light, or that 6 is heavy. So for the last weighing, do 1 vs. 2. If equal, #6 is the heavy coin. If not equal, whichever of 1 or 2 is lighter is the answer.</p>
<p>If (1, 2, 5) > (4, 6, 9), then the possibilities are that #5 is heavy, or that #4 is light. For the last weighing, do 1 vs. 4. If equal, #5 is the heavy coin. If 1 > 4, then #4 is light. (Note that its not possible for 1 < 4).</p>
<p>Ok, I have way too much time on my hands. :-P Did that make any sense?</p>