3 ms·
What's really interesting is that there are probabilistic programming languages where you can write a program that does a simulation just like you did, but the
by jules 13y ago
What's really interesting is that there are probabilistic programming languages where you can write a program that does a simulation just like you did, but the execution engine can compute the probabilities exactly and much faster too. It does this by computing along all possible paths in the program, and keeping track of the probability mass of each path, and then summing them all up in the end.
http://en.wikipedia.org/wiki/Probabilistic_programming_language http://en.wikipedia.org/wiki/Probabilistic_programming_langu...
- crntaylor 13y agoCompletely shameless plug for a tiny probabilistic programming language that I wrote as an embedded DSL in Haskell: https://github.com/chris-taylor/hs-probability https://github.com/chris-taylor/hs-probability The code that solves this problem is: solve = do coin <- choose (999/1000) fair biased tosses <- replicateM 10 coin condition (tosses == replicate 10 Head) nextToss <- coin return nextToss where fair = choose (1/2) Head Tail biased = certainly Head