Here’s code to compute the probability empirically (I got an answer of 0.2051384 for 10000 draws. It’s written in C# but can be readily converted to other functional languages such as Haskell).
var cards = new[] { "AH", "AS", "2C", "2D" };
var pairs = cards.Combinations (2);
var pairsWithAce = pairs.Where (p => p.Any (c => c.Contains ("A")));
var drawsWithAce =
(
from i in Enumerable.Range (1, 10000)
let randomPairWithAce = pairsWithAce.ElementAt (rand.Next (pairsWithAce.Count()))
let isPairOfAces = randomPairWithAce.All (c => c.Contains ("A"))
let randomAce = isPairOfAces
? randomPairWithAce.ElementAt (rand.Next (2))
: randomPairWithAce.Single (c => c.Contains ("A"))
let isRandomAceASpade = randomAce == "AS"
select new
{
isPairOfAces,
isRandomAceASpade
}
).ToArray();
var conditionalProbability =
(float)drawsWithAce.Count (d => d.isPairOfAces && d.isRandomAceASpade) /
(float)drawsWithAce.Count (d => d.isRandomAceASpade);
Notice that isPairOfAces is not a function of isRandomAceASpade. In other words, the suit of the random ace doesn’t affect the probability of there being a pair of aces. Computer programs don’t suffer Information Bias. OTOH I do so let me know if I screwed up… ;)
For those interested in the complete working code:
using System;
using System.Collections.Generic;
using System.Linq;
static class Program
{
static void Main()
{
...<put code above here>...
}
public static Random rand = new Random();
// Returns all possible combinations of size k from a sequence of elements
public static IEnumerable<IEnumerable<T>> Combinations<T>(this IEnumerable<T> elements, int k)
{
return k == 0 ? new[] { new T[0] } :
elements.SelectMany((e, i) =>
elements.Skip(i + 1).Combinations(k - 1).Select(c => (new[] { e }).Concat(c)));
}
}
Here’s code to compute the probability empirically (I got an answer of 0.2051384 for 10000 draws. It’s written in C# but can be readily converted to other functional languages such as Haskell).
Notice that isPairOfAces is not a function of isRandomAceASpade. In other words, the suit of the random ace doesn’t affect the probability of there being a pair of aces. Computer programs don’t suffer Information Bias. OTOH I do so let me know if I screwed up… ;)
For those interested in the complete working code: