Assignment:
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.
Provide complete and step by step solution for the question and show calculations and use formulas.