<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Recreations on aliquote.org</title><link>https://aliquote.org/tags/recreations/</link><description>Recent content in Recreations on aliquote.org</description><generator>Hugo -- gohugo.io</generator><language>en</language><lastBuildDate>Mon, 09 Nov 2026 19:59:40 +0100</lastBuildDate><atom:link href="https://aliquote.org/tags/recreations/index.xml" rel="self" type="application/rss+xml"/><item><title>Expected tosses for consecutive Heads</title><link>https://aliquote.org/post/two-heads-vs-three/</link><pubDate>Mon, 09 Nov 2026 19:59:40 +0100</pubDate><guid>https://aliquote.org/post/two-heads-vs-three/</guid><description>&lt;p&gt;I came across the following puzzle, &lt;a href="https://pratikpoddarcse.blogspot.com/2009/10/lets-say-keep-tossing-fair-coin-until.html"&gt;Expected Tosses for Consecutive Heads: 2
Heads vs 3 Heads Puzzle&lt;/a&gt;, this morning:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Let&amp;rsquo;s say A keep tossing a fair coin, until he get 2 consecutive heads, define
X to be the number of tosses for this process; B keep tossing another fair
coin, until he get 3 consecutive heads, define Y to be the number of the
tosses for this process.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;blockquote&gt;
&lt;ol&gt;
&lt;li&gt;Calculate P{X&amp;gt;Y}&lt;/li&gt;
&lt;li&gt;What&amp;rsquo;s the expected value of X&lt;/li&gt;
&lt;li&gt;What&amp;rsquo;s the expected value of Y&lt;/li&gt;
&lt;/ol&gt;
&lt;/blockquote&gt;
&lt;p&gt;Sure we can enumerate all possible states as the author did. However, we know
that $X$ follows a modified Geometrical law: for $k \geq 2$ (we can&amp;rsquo;t get 2
heads with one trial only) $\Pr(X = k) = \frac{F_{k-1}}{2^k}$, where $F_{k-1}$
is the $k - 1$th term of the Fibonacci series. Assuming a fair coin ($p = 1/2$),
the expected number of trials before observing $k = 2$ Heads is given by
$2(2^k - 1) = 2^{k+1} - 2$. For $k = 2$ we would need 6 flips.&lt;/p&gt;
&lt;p&gt;The transition matrix for the corresponding 3-state Markov chain, where state 0 =
0 consecutive Head, state 1 = 1 consecutive Head, and State 2 = 2 consecutive
Heads (absorbing state), is:&lt;/p&gt;
&lt;p&gt;$$
\begin{pmatrix}
0.5 &amp;amp; 0.5 &amp;amp; 0 \cr
0.5 &amp;amp; 0 &amp;amp; 0.5 \cr
0 &amp;amp; 0 &amp;amp; 1 \cr
\end{pmatrix}
$$&lt;/p&gt;
&lt;p&gt;Let&amp;rsquo;s look at the transient states 0 and 1:&lt;/p&gt;
&lt;p&gt;$$
Q = \begin{pmatrix}
0.5 &amp;amp; 0.5 \cr
0.5 &amp;amp; 0 \cr
\end{pmatrix}
$$&lt;/p&gt;
&lt;p&gt;The fundamental matrix, $N = (I - Q)^{-1}$, is derived from:&lt;/p&gt;
&lt;p&gt;$$
I - Q = \begin{pmatrix} 1 &amp;amp; 0 \cr 0 &amp;amp; 1 \end{pmatrix} - \begin{pmatrix} 0.5 &amp;amp; 0.5 \cr 0.5 &amp;amp; 0 \end{pmatrix} = \begin{pmatrix} 0.5 &amp;amp; -0.5 \cr -0.5 &amp;amp; 1 \end{pmatrix}
$$&lt;/p&gt;
&lt;p&gt;So that $N = \begin{pmatrix} 4 &amp;amp; 2 \cr 2 &amp;amp; 2 \end{pmatrix}$. The sum of the
first row reflects the number of time we will visit state 0 and state 1 before
absorption, i.e. 6 flips like we said earlier.&lt;/p&gt;
&lt;p&gt;The random variable Y follows a similar law, and the expected number of flips
before $k = 3$ Heads therefore is 14.&lt;sup id="fnref:1"&gt;&lt;a href="#fn:1" class="footnote-ref" role="doc-noteref"&gt;1&lt;/a&gt;&lt;/sup&gt;&lt;/p&gt;
&lt;p&gt;Back to the first question. The probability can be found by summing the joint
probabilities:
$P(X &amp;gt; Y) = \sum_{y=3}^\infty\sum_{x=y+1}^\infty P(X = x) \cdot P(Y = y)$ (the
second lower bound results from the strict inequality constraint, $X &amp;gt; Y$). Or
developing the system of equations for all possible joint states like the
original author did. Instead of Markov chain analysis, I tried to use the
transition matrices and I defined probability distribution in Mathematica as
follows:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-fallback" data-lang="fallback"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;X = DiscreteMarkovProcess[1, {{1/2, 1/2, 0}, {1/2, 0, 1/2}, {0, 0, 1}}];
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;Y = DiscreteMarkovProcess[
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; 1, {{1/2, 1/2, 0, 0}, {1/2, 0, 1/2, 0}, {1/2, 0, 0, 1/2}, {0, 0, 0,
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; 1}}];
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;distX = FirstPassageTimeDistribution[X, 3];
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;distY = FirstPassageTimeDistribution[Y, 4];
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;The PDFs look okay but
&lt;code&gt;Probability[x &amp;gt; y, {x \[Distributed] distX, y \[Distributed] distY}]&lt;/code&gt; took way
too much time to me. I suspect Mathematica is using symbolic computation under
the hood or get lost in an infinite sum. No luck with &lt;code&gt;NProbability&lt;/code&gt; either.
This is something I have to investigate and I will post an addendum, eventually.&lt;/p&gt;
&lt;figure&gt;&lt;img src="https://aliquote.org/img/two-heads-vs-three-pdf.png"&gt;
&lt;/figure&gt;
&lt;p&gt;In the meantime, I decided to use a different approach and used Fibonacci and
Tribonacci numbers to find the answer quickly, that is by summing the joint
probabilities after precomputing sum of the values for X:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-fallback" data-lang="fallback"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;trib = RSolveValue[{a[n] == a[n - 1] + a[n - 2] + a[n - 3], a[0] == 0,
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; a[1] == 0, a[2] == 1}, a, n];
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;pdfX[k_] := Fibonacci[k - 1]/2^k;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;pdfY[k_] := trib[k - 1]/2^k;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;tailX[n_] =
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; FullSimplify[Sum[pdfX[k], {k, n + 1, Infinity}],
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; Assumptions -&amp;gt; n &amp;gt;= 2];
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;Sum[pdfY[n]*tailX[n], {n, 3, Infinity}] // FullSimplify
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;We get the expected result, $\frac{361}{1699}$ (0.2125).&lt;/p&gt;
&lt;div class="music" align="right"&gt;
&lt;p&gt;♪ Lauren Hoffman • &lt;em&gt;The Chemical&lt;/em&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;div class="footnotes" role="doc-endnotes"&gt;
&lt;hr&gt;
&lt;ol&gt;
&lt;li id="fn:1"&gt;
&lt;p&gt;It is also possible to use generating functions to achieve the same
conclusion, see this &lt;a href="https://math.stackexchange.com/a/2845284"&gt;math.SE&lt;/a&gt; thread.&amp;#160;&lt;a href="#fnref:1" class="footnote-backref" role="doc-backlink"&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;</description></item></channel></rss>