title: Simulating the probability that Alice and Bob flip the same number of tails
body: <blockquote>
    <p>Alice tosses a fair coin n independent times and Bob tosses a fair
    coin m independent times. What is the probability that they have equal
    numbers of tails?</p>
  </blockquote>
  
  <p>Analytically, the probability is given as</p>
  
  <p>(n+m choose m) (1/2^(n+m))</p>
  
  <p>so for example, if n=5 and m=7 the desired probability is</p>
  
  <p>(5+7 choose 7) (1/2^(5+7)) = 0.193</p>
  
  <p>I am interested in figuring out how to simulate this situation in R. I have so far,</p>
  
  <pre><code>coin=c("H","T")
  n=5
  m=7
  u=replicate(10^6,sample(coin,n,repl=T))
  v=replicate(10^6,sample(coin,m,repl=T))
  </code></pre>
  
  <p>but I'm not sure how to proceed in finding how often the number of tails in a given sample is equal for both u and v.</p>
  
  <p>I tried using the table() function but</p>
  
  <pre><code>table(u)
  table(v)
  </code></pre>
  
  <p>just returns the total number of heads and tails in each of the samples, combined.</p>