Another Programming Blog

(mostly iOS and Ruby on Rails)

Average Salary

To calculate the average salary of a group of people anonymously:

Person #1 invents a (high enough) random number and adds his salary to it. He passes the sum to person #2. #2 adds his salary and passes the new sum to person #3. And so forth, until #1 eventually gets the last sum from the last participant.

Person #1 subtracts the initial random number and divides the result by the number of people. The result is the average salary.

Caveats: People can lie and the number of participants should be big enough. (With 2 people person #1 will just find out the other persons salary.)

P.S.: You can follow me on Twitter.