Here is my answer to the specified problem..
For better understanding :
Assume caps are numbered as 0, 1, 2, 3, and 4.
1. 5 friends also label themself as 0, 1, 2, 3, and 4 before attending
the party.
2. Each persons prediction is as follows (Sum(Other_4_Cap_Numbers) +
prediction) mod 5 = Own_Label.
i.e. Say first person assumes that the total sum of caps mod 5 is
equal to 0.
second person assumes that the total sum of caps mod 5 is
equal to 1.
third person assumes that the total sum of caps mod 5 is
equal to 2.
forth person assumes that the total sum of caps mod 5 is
equal to 3.
fifth person assumes that the total sum of caps mod 5 is
equal to 4.
based on the above assumptions every one come up with their
own predictions. Catch here is at least one of their prediction is
always right.
A) Sample case : 2 3 3 0 1
person 1 calculation : (7 + prediction) mod 5 = 0 ==> Says
prediction as 3
person 2 calculation : (6 + prediction) mod 5 = 1 ==> Says
prediction as 0
person 3 calculation : (6 + prediction) mod 5 = 2 ==> Says
prediction as 1
person 4 calculation : (9 + prediction) mod 5 = 3 ==> Says
prediction as 4
person 5 calculation : (8 + prediction) mod 5 = 4 ==> Says
prediction as 1
In this case 5th person is correct.
B) Sample case : 4 0 0 1 3
person 1 calculation : (4 + prediction) mod 5 = 0 ==> Says
prediction as 1
person 2 calculation : (8 + prediction) mod 5 = 1 ==> Says
prediction as 3
person 3 calculation : (8 + prediction) mod 5 = 2 ==> Says
prediction as 4
person 4 calculation : (7 + prediction) mod 5 = 3 ==> Says
prediction as 1
person 5 calculation : (5 + prediction) mod 5 = 4 ==> Says
prediction as 4
In this case 4th person is correct.
Now it is your job is to figure out why this solution works..
-- SURI