Posts

Showing posts with the label probabilities

Stupid code fragments, part two

Probabilities are hard. As an example, there's a known puzzle: a family has two children; if one of them is a girl, what is the probability that the other one is also a girl? The answer, un-intuitively, is not 1/2 but 1/3. There are various explanations but – as with the Monty Python puzzle years ago – I wanted to write code to check it out, so I wrote the following using LinqPad: void Main() { var rnd = new Random(); // Generate a random set of families with two children; true means girl, false means boy var all = Enumerable.Range(1, 10000).Select(_ => new Pair(rnd.Next(2) == 0, rnd.Next(2) == 0)).ToList(); // Extract only the families with at least one girl var oneGirl = all.Where(it => it.First || it.Second).ToList(); // Out of those families, how many have two girls? The result should be 1/3rd var otherGirl = oneGirl.Where(it => it.First && it.Second).ToList(); Console.Wri...

More on probabilities

This is in regards to the often-repeated saying "improbable events happen all the time" (even Dembski says that... which only serves to show that even people on "my" side can be idiots). I just read something that was so apropos of this: Heroic Law of Probabilities: One-in-a-million chances happen 9/10 (Look for it on this page , it makes more sense in context.) That is just too great for words, I will keep quoting that "law" every time the subject comes up. I have to read that story , even though I'm not a fan of Marvel stuff. (Plus, the main character has a Romanian name. Yay :P)