A street magician has a tray of trick coins, each stamped with how often it lands heads. Behind a screen he flips one of them and shows you every flip. Write most_likely_coin(flips, coins): return the position on the tray of the coin most likely to have thrown exactly these flips(0 for the first coin).
The magician flipped one of two coins 50 times: 31 heads. The obvious pick is the coin closest to 62% heads, the 90% coin. Then follow each coin’s chance of throwing exactly these flips, one flip at a time: every tail costs the 90% coin dearly. The goal is the coin whose chance ends highest. Your most_likely_coin() picks it.
most_likely_coin(flips, coins)| flips | what the magician threw, in order: 1 = heads, 0 = tails (a list) | e.g. [1, 1, 1, 1, 1, 1, 1, 1] |
| coins | each coin's chance of landing heads, e.g. [0.3, 0.9] (a list) | e.g. [0.5, 0.9, 0.2] |
| returns | the position in coins of the coin most likely to have thrown these flips, e.g. 0 | |