Eight coins are identical in appearance, but one coin is either heavier or lighter than the others, which all weigh the same.
Describe an algorithm that identifies the bad coin in at most three weighings and also determines whether it is heavier or lighter than the others, using only a pan balance.
Solution describes an algorithm to detect the single bad coin, interspersed with pseudo code, analysis and detailed explanations on hows and whys behind correct working of this algorithm.