Created
May 15, 2017 11:48
-
-
Save dat-boris/51998756c67c3097249bd2ee6c69dc79 to your computer and use it in GitHub Desktop.
My naive attempt to reverse distribution of "second guessers" based on result from Thaler guessing game
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python3 | |
| """ | |
| Thaler guessing game | |
| --------------------- | |
| https://en.wikipedia.org/wiki/Guess_2/3_of_the_average | |
| Guessing how much people guess ahead? | |
| > When performed among ordinary people it is usually found that the winner | |
| > guess is much higher than 0, e.g., 21.6 was the winning value in a large | |
| > internet-based competition organized by the Danish newspaper Politiken. | |
| > This included 19,196 people and with a prize of 5000 Danish kroner | |
| Result | |
| ----- | |
| * 26% ppl think 1 step ahead | |
| * 35% ppl think 2 step ahead | |
| * 24% ppl think 3 step ahead | |
| * 10% ppl think 4 step ahead | |
| Detail log | |
| ----------- | |
| ``` | |
| # 10% migration | |
| Avg: 22.46337448559671 Seq: [316, 347, 207, 90, 40] | |
| Avg: 21.69012345679012 Seq: [285, 341, 220, 103, 51] | |
| Avg: 20.949382716049378 Seq: [257, 333, 231, 116, 63] | |
| Final Avg: 20.949382716049378 Seq: [257, 333, 231, 116, 63] | |
| ``` | |
| ``` | |
| # 5% migration | |
| Avg: 22.235390946502054 Seq: [298, 355, 221, 94, 32] | |
| Avg: 21.87572016460905 Seq: [284, 351, 228, 100, 37] | |
| Avg: 21.511111111111106 Seq: [270, 347, 234, 107, 42] | |
| Final Avg: 21.511111111111106 Seq: [270, 347, 234, 107, 42] | |
| ``` | |
| ``` | |
| # 2% migration | |
| Avg: 21.686831275720163 Seq: [271, 352, 243, 106, 28] | |
| Avg: 21.548148148148147 Seq: [266, 350, 245, 109, 30] | |
| Final Avg: 21.548148148148147 Seq: [266, 350, 245, 109, 30] | |
| ``` | |
| """ | |
| import math | |
| RATIO = 2/3 | |
| TOP_GUESS = 5 | |
| GUESTS = 1000 | |
| TARGET_AVG = 21.6 | |
| STEP = 0.02 | |
| SEQ = [50 * math.pow(RATIO, i) for i in range(1, TOP_GUESS+1)] | |
| def cal_avg_for_order(number_of_guesses_for_each_step): | |
| # assuming that there are more intelligent guests than non-intelligent | |
| assert len(number_of_guesses_for_each_step) == TOP_GUESS | |
| sum_of_guesses = 0 | |
| for o,s in zip(number_of_guesses_for_each_step, SEQ): | |
| sum_of_guesses += o*s | |
| return (sum_of_guesses / GUESTS) | |
| def make_smarter(seq): | |
| for i in reversed(range(len(seq)-1)): | |
| diff = math.floor(seq[i] * STEP) | |
| seq[i] -= diff | |
| seq[i+1] += diff | |
| return seq | |
| if __name__=='__main__': | |
| print("Sequence: {}".format(SEQ)) | |
| # Test the average | |
| current_sequence = [1000,0,0,0,0] | |
| current_avg = cal_avg_for_order(current_sequence) | |
| print("Start avg - assuming 1 degree cleverness: {}".format(current_avg)) | |
| assert 33 < current_avg < 34 | |
| while current_avg >= TARGET_AVG: | |
| current_sequence = make_smarter(current_sequence) | |
| current_avg = cal_avg_for_order(current_sequence) | |
| print("Avg: {} Seq: {}".format(current_avg, current_sequence)) | |
| print("Final Avg: {} Seq: {}".format(current_avg, current_sequence)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment