{"id":2739,"date":"2020-01-18T12:43:56","date_gmt":"2020-01-18T18:43:56","guid":{"rendered":"https:\/\/laurentlessard.com\/bookproofs\/?p=2739"},"modified":"2020-01-20T00:01:54","modified_gmt":"2020-01-20T06:01:54","slug":"delirious-ducks","status":"publish","type":"post","link":"https:\/\/laurentlessard.com\/bookproofs\/delirious-ducks\/","title":{"rendered":"Delirious ducks"},"content":{"rendered":"<p>This week&#8217;s <a href=\"https:\/\/fivethirtyeight.com\/features\/can-you-track-the-delirious-ducks\/\">Riddler Classic<\/a> is about random walks on a lattice:<\/p>\n<blockquote><p>\nTwo delirious ducks are having a difficult time finding each other in their pond. The pond happens to contain a 3\u00d73 grid of rocks.<\/p>\n<p>Every minute, each duck randomly swims, independently of the other duck, from one rock to a neighboring rock in the 3\u00d73 grid \u2014 up, down, left or right, but not diagonally. So if a duck is at the middle rock, it will next swim to one of the four side rocks with probability 1\/4. From a side rock, it will swim to one of the two adjacent corner rocks or back to the middle rock, each with probability 1\/3. And from a corner rock, it will swim to one of the two adjacent side rocks with probability 1\/2.<\/p>\n<p>If the ducks both start at the middle rock, then on average, how long will it take until they\u2019re at the same rock again? (Of course, there\u2019s a 1\/4 chance that they\u2019ll swim in the same direction after the first minute, in which case it would only take one minute for them to be at the same rock again. But it could take much longer, if they happen to keep missing each other.)<\/p>\n<p>Extra credit: What if there are three or more ducks? If they all start in the middle rock, on average, how long will it take until they are all at the same rock again?\n<\/p><\/blockquote>\n<p>Here is my solution:<br \/>\n<a href=\"javascript:Solution('soln_ducks','toggle_ducks')\" id=\"toggle_ducks\">[Show Solution]<\/a><\/p>\n<div id=\"soln_ducks\" style=\"display: none\">\n<h3>One duck<\/h3>\n<p>We will solve this problem by starting with a simpler one and building up to the full problem. Let&#8217;s consider a single duck on the grid of rocks. At each step, the duck moves randomly to one of the other nearby rocks. We can describe this process using a <a href=\"https:\/\/en.wikipedia.org\/wiki\/Markov_chain\">Markov chain<\/a>. Each state is a different rock, and the directed edges are labeled with the transition probabilities. Here is a diagram of what the Markov chain looks like:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/laurentlessard.com\/bookproofs\/wp-content\/uploads\/2020\/01\/delirious_ducks-300x294.png\" alt=\"\" width=\"300\" height=\"294\" class=\"aligncenter size-medium wp-image-2740\" srcset=\"https:\/\/laurentlessard.com\/bookproofs\/wp-content\/uploads\/2020\/01\/delirious_ducks-300x294.png 300w, https:\/\/laurentlessard.com\/bookproofs\/wp-content\/uploads\/2020\/01\/delirious_ducks-1024x1003.png 1024w, https:\/\/laurentlessard.com\/bookproofs\/wp-content\/uploads\/2020\/01\/delirious_ducks-768x752.png 768w, https:\/\/laurentlessard.com\/bookproofs\/wp-content\/uploads\/2020\/01\/delirious_ducks-1200x1176.png 1200w, https:\/\/laurentlessard.com\/bookproofs\/wp-content\/uploads\/2020\/01\/delirious_ducks.png 1276w\" sizes=\"auto, (max-width: 300px) 85vw, 300px\" \/><\/p>\n<p>If we number the states in the same way as above, then the transition matrix for this Markov chain is:<br \/>\n\\[<br \/>\nP = \\begin{bmatrix}<br \/>\n0 &#038; \\tfrac12 &#038; 0 &#038; \\tfrac12 &#038; 0 &#038; 0 &#038; 0 &#038; 0 &#038; 0 \\\\<br \/>\n\\tfrac13 &#038; 0 &#038; \\tfrac13 &#038; 0 &#038; \\tfrac13 &#038; 0 &#038; 0 &#038; 0 &#038; 0 \\\\<br \/>\n0 &#038; \\tfrac12 &#038; 0 &#038; 0 &#038; 0 &#038; \\tfrac12 &#038; 0 &#038; 0 &#038; 0 \\\\<br \/>\n\\tfrac13 &#038; 0 &#038; 0 &#038; 0 &#038; \\tfrac13 &#038; 0 &#038; \\tfrac13 &#038; 0 &#038; 0 \\\\<br \/>\n0 &#038; \\tfrac14 &#038; 0 &#038; \\tfrac14 &#038; 0 &#038; \\tfrac14 &#038; 0 &#038; \\tfrac14 &#038; 0 \\\\<br \/>\n0 &#038; 0 &#038; \\tfrac13 &#038; 0 &#038; \\tfrac13 &#038; 0 &#038; 0 &#038; 0 &#038; \\tfrac13 \\\\<br \/>\n0 &#038; 0 &#038; 0 &#038; \\tfrac12 &#038; 0 &#038; 0 &#038; 0 &#038; \\tfrac12 &#038; 0 \\\\<br \/>\n0 &#038; 0 &#038; 0 &#038; 0 &#038; \\tfrac13 &#038; 0 &#038; \\tfrac13 &#038; 0 &#038; \\tfrac13 \\\\<br \/>\n0 &#038; 0 &#038; 0 &#038; 0 &#038; 0 &#038; \\tfrac12 &#038; 0 &#038; \\tfrac12 &#038; 0 \\\\<br \/>\n\\end{bmatrix}<br \/>\n\\]The way to interpret this matrix is that $P_{ij}$ is the probability that we will transition from $i$ to $j$. This explains why the rows sum to 1 (the matrix is <a href=\"https:\/\/en.wikipedia.org\/wiki\/Stochastic_matrix\">right-stochastic<\/a>). We can express this fact neatly using matrix multiplication as: $P \\mathbf{1} = \\mathbf{0}$, where $\\mathbf{0}$ and $\\mathbf{1}$ are column vectors of all-zeros and all-ones, repectively. Mathematically, we can propagate probability distributions through this Markov chain via matrix multiplication. If we have some initial distribution $\\mathbf{a}$ across the states, for example<br \/>\n\\[<br \/>\n\\mathbf{a}^\\mathsf{T} = \\begin{bmatrix} \\tfrac12 &#038; \\tfrac12 &#038; 0 &#038; 0 &#038; 0 &#038; 0 &#038; 0 &#038; 0 &#038; 0 \\end{bmatrix}<br \/>\n\\]i.e. we are equally likely to be in states 1 or 2. Then at the next step, the probability distribution will transition $\\mathbf{a}\\to\\mathbf{b}$ with<br \/>\n\\[<br \/>\n\\mathbf{b}^\\mathsf{T} = \\mathbf{a}^\\mathsf{T}P = \\begin{bmatrix} \\tfrac16 &#038; \\tfrac14 &#038; \\tfrac16 &#038; \\tfrac14 &#038; \\tfrac16 &#038; 0 &#038; 0 &#038; 0 &#038; 0 \\end{bmatrix}<br \/>\n\\]So in the next step, we might be in states 1, 2, 3, 4, 5 with the associated probabilities above.<\/p>\n<p>It&#8217;s important to distinguish <em>states<\/em> e.g. $\\{1,2,\\dots,9\\}$ from <em>distributions over states<\/em>, which are the vectors of probabilities such as the $\\mathbf{a}$ and $\\mathbf{b}$ used above. In the case where a distribution across states is <a href=\"https:\/\/en.wikipedia.org\/wiki\/Degenerate_distribution\">degenerate<\/a>, i.e. concentrated entirely on a particular state $s$, then I&#8217;ll use the following notation to denote the corresponding distribution over states:<br \/>\n\\[<br \/>\n\\left( \\mathbf{e}_s\\right)_i = \\begin{cases} 1 &#038; \\text{if } i=s \\\\ 0 &#038; \\text{otherwise} \\end{cases}<br \/>\n\\]So, for example, $\\mathbf{e}_2^\\mathsf{T} = \\begin{bmatrix} 0 &#038; 1 &#038; 0 &#038; 0 &#038; 0 &#038; 0 &#038; 0 &#038; 0 &#038; 0 \\end{bmatrix}$.<\/p>\n<h3>Stopping time<\/h3>\n<p>We are interested in the expected <a href=\"https:\/\/en.wikipedia.org\/wiki\/Hitting_time\">hitting time<\/a>, which is the number of steps it will take on average to travel from some initial state $s$ to some target state $t \\in \\mathcal{T}$. To keep this general, I&#8217;m assuming there can be multiple target states, indicated by the set $\\mathcal{T}$. Let&#8217;s define $\\mathbf{q}_s$ to be the expected hitting time to get from state $s$ to any state in our terminal set $\\mathcal{T}$. It turns out that $\\mathbf{q}$ satisfies the recursive relationship:<br \/>\n\\[<br \/>\n\\mathbf{q}_s = \\begin{cases}<br \/>\n0 &#038; \\text{if }s \\in \\mathcal{T} \\\\<br \/>\n1 + \\sum_{i} P_{si} \\mathbf{q}_i &#038; \\text{otherwise}<br \/>\n\\end{cases}<br \/>\n\\]The first case is clear: if we start in the terminal set, then we have already arrived, so the hitting time is zero. If we are outside the terminal set, then the expected hitting time will be $1$ plus the weighted sum of the hitting times of wherever we end up after the next transition. The recursion above is essentially the <a href=\"https:\/\/en.wikipedia.org\/wiki\/Bellman_equation\">Bellman equation<\/a> from <a href=\"https:\/\/en.wikipedia.org\/wiki\/Dynamic_programming\">dynamic programming<\/a>.<\/p>\n<p>Define the vector $\\mathbf{t}_i = \\begin{cases} 0 &#038; \\text{if }i \\in \\mathcal{T}\\\\ 1 &#038; \\text{otherwise} \\end{cases}$.<br \/>\nWe can rewrite the equation above in concise vector form as:<br \/>\n\\[<br \/>\n\\mathbf{q} = \\textrm{diag}(\\mathbf{t}) \\left( \\mathbf{1} + P \\mathbf{q} \\right)<br \/>\n\\]Using the fact that $\\textrm{diag}(\\mathbf{t})\\mathbf{1} = \\mathbf{t}$, we can further simplify and obtain:<br \/>\n\\[<br \/>\n\\left( I-\\textrm{diag}(\\mathbf{t}) P \\right) \\mathbf{q} = \\mathbf{t}<br \/>\n\\]For the case of one duck, if we set the terminal set to be $\\mathcal{T} = \\{5\\}$, then we substitute $\\mathbf{t} = \\begin{bmatrix} 1 &#038; 1 &#038; 1 &#038; 1 &#038; 0 &#038; 1 &#038; 1 &#038; 1 &#038; 1 \\end{bmatrix}^\\mathsf{T}$ above and obtain:<br \/>\n\\[<br \/>\n\\begin{bmatrix}<br \/>\n1 &#038; -\\tfrac12 &#038; 0 &#038; -\\tfrac12 &#038; 0 &#038; 0 &#038; 0 &#038; 0 &#038; 0 \\\\<br \/>\n-\\tfrac13 &#038; 1 &#038; -\\tfrac13 &#038; 0 &#038; -\\tfrac13 &#038; 0 &#038; 0 &#038; 0 &#038; 0 \\\\<br \/>\n0 &#038; -\\tfrac12 &#038; 1 &#038; 0 &#038; 0 &#038; -\\tfrac12 &#038; 0 &#038; 0 &#038; 0 \\\\<br \/>\n-\\tfrac13 &#038; 0 &#038; 0 &#038; 1 &#038; -\\tfrac13 &#038; 0 &#038; -\\tfrac13 &#038; 0 &#038; 0 \\\\<br \/>\n0 &#038; 0 &#038; 0 &#038; 0 &#038; 1 &#038; 0 &#038; 0 &#038; 0 &#038; 0 \\\\<br \/>\n0 &#038; 0 &#038; -\\tfrac13 &#038; 0 &#038; -\\tfrac13 &#038; 1 &#038; 0 &#038; 0 &#038; -\\tfrac13 \\\\<br \/>\n0 &#038; 0 &#038; 0 &#038; -\\tfrac12 &#038; 0 &#038; 0 &#038; 1 &#038; -\\tfrac12 &#038; 0 \\\\<br \/>\n0 &#038; 0 &#038; 0 &#038; 0 &#038; -\\tfrac13 &#038; 0 &#038; -\\tfrac13 &#038; 1 &#038; -\\tfrac13 \\\\<br \/>\n0 &#038; 0 &#038; 0 &#038; 0 &#038; 0 &#038; -\\tfrac12 &#038; 0 &#038; -\\tfrac12 &#038; 1 \\\\<br \/>\n\\end{bmatrix}<br \/>\n\\begin{bmatrix}\\mathbf{q}_1\\vphantom{\\tfrac12} \\\\ \\mathbf{q}_2\\vphantom{\\tfrac12} \\\\ \\mathbf{q}_3\\vphantom{\\tfrac12} \\\\<br \/>\n\\mathbf{q}_4\\vphantom{\\tfrac12} \\\\ \\mathbf{q}_5\\vphantom{\\tfrac12} \\\\ \\mathbf{q}_6\\vphantom{\\tfrac12} \\\\<br \/>\n\\mathbf{q}_7\\vphantom{\\tfrac12} \\\\ \\mathbf{q}_8\\vphantom{\\tfrac12} \\\\ \\mathbf{q}_9\\vphantom{\\tfrac12} \\end{bmatrix}<br \/>\n= \\begin{bmatrix}<br \/>\n1\\vphantom{\\tfrac12} \\\\1\\vphantom{\\tfrac12} \\\\1\\vphantom{\\tfrac12} \\\\1\\vphantom{\\tfrac12} \\\\<br \/>\n0\\vphantom{\\tfrac12} \\\\1\\vphantom{\\tfrac12} \\\\1\\vphantom{\\tfrac12} \\\\1\\vphantom{\\tfrac12} \\\\1\\vphantom{\\tfrac12}<br \/>\n\\end{bmatrix}<br \/>\n\\]Inverting this matrix and solving for $\\mathbf{q}$, here is the result in array form:<br \/>\n\\[<br \/>\n\\begin{array}{|c|c|c|} \\hline<br \/>\n\\mathbf{q}_1 = 6 &#038; \\mathbf{q}_2 = 5 &#038; \\mathbf{q}_3 = 6 \\\\ \\hline<br \/>\n\\mathbf{q}_4 = 5 &#038; \\mathbf{q}_5 = 0 &#038; \\mathbf{q}_6 = 5 \\\\ \\hline<br \/>\n\\mathbf{q}_7 = 6 &#038; \\mathbf{q}_8 = 5 &#038; \\mathbf{q}_9 = 6 \\\\ \\hline<br \/>\n\\end{array}<br \/>\n\\]So if we start at node 1, it will take us on average 6 moves to reach node 5. It is by no means obvious that the expected hitting times should be integers, since they represent an average path length over an infinite number of possible paths. They just turn out to be integers in this case. The symmetry observed here also makes sense, and we could leverage it to simplify the problem to a Markov chain with only 3 states, but I&#8217;ll leave that as an exercise to the reader! (the reason I didn&#8217;t do this from the start is that I want to generalize easily to the multi-duck case, and the symmetries there are more complicated).<\/p>\n<p>What about the variant where we start at the origin but we want to know how much time it will take us to return to the origin? In this case, we simply start counting from our second move, and we add 1 to the answer to account for the move we skipped. If we start at node 5, i.e. our initial distribution is $\\mathbf{e}_5^\\mathsf{T}$, then our distribution on the second turn is $\\mathbf{e}_5^\\mathsf{T} P$, and so the expected number of moves to start at 5 and return to 5 is:  $\\mathbf{e}_5^\\mathsf{T} P \\mathbf{q} + 1 = 6$.<\/p>\n<h3>Two ducks<\/h3>\n<p>At first glance, the two-duck version might seem much more challenging than the on-duck version. As we shall see, the problem is essentially the same once we look at it the right way. The key is to imagine a Markov chain where instead of the states being $\\{1,2,\\dots,9\\}$, the states are $\\{(1,1), (1,2), \\dots, (9,9)\\}$. In other words, there are 81 states, consisting of all possible pairs $(s_1,s_2)$, where $s_i \\in \\{1,2,\\dots,9\\}$ is the position of duck $i$.<\/p>\n<p>What would be the transition matrix for such a Markov chain? The transition probability $(a_1, a_2) \\to (b_1, b_2)$ is simply $P_{a_1,b_1} P_{a_2,b_2}$, i.e. the product of the respective transition probabilities for each duck. This means that if we order our states according to the first duck first (<a href=\"https:\/\/en.wikipedia.org\/wiki\/Lexicographical_order\">lexicographical ordering<\/a>), then the transition matrix for this augmented Markov chain will be $P\\otimes P$, where $\\otimes$ is the <a href=\"https:\/\/en.wikipedia.org\/wiki\/Kronecker_product\">Kronecker product<\/a>.<\/p>\n<p>So we can solve the problem in a very similar fashion. This time, our terminal set consists of all the nodes $(s_1, s_2)$ where $s_1=s_2$. There are 9 such nodes, and we can form the associated $\\mathbf{t}$ by evaluating $\\mathbf{t} = \\mathbf{1}-\\textrm{vec}(I)$, where $\\mathrm{vec}$ is the <em>vectorized<\/em> version of the matrix, which you obtain by enumerating the columns. For example:<br \/>\n\\[<br \/>\n\\mathrm{vec} \\begin{bmatrix}a_{11} &#038; a_{12} &#038; a_{13} \\\\<br \/>\na_{21} &#038; a_{22} &#038; a_{23} \\\\<br \/>\na_{31} &#038; a_{32} &#038; a_{33}<br \/>\n\\end{bmatrix} =<br \/>\n\\begin{bmatrix}<br \/>\na_{11} \\\\ a_{21} \\\\ a_{31} \\\\ a_{12} \\\\ a_{22} \\\\ a_{32} \\\\ a_{13} \\\\ a_{23} \\\\ a_{33} \\end{bmatrix}<br \/>\n\\]the new equation for $\\mathcal{q}$ is $\\bigl( I-\\textrm{diag}(\\mathbf{t}) (P\\otimes P) \\bigr) \\mathbf{q} = \\mathbf{t}$ and the solution to the problem where you start at $(5,5)$ and want to know the expect time it takes for us to reach the terminal set (where the two ducks are on the same rock) can be computed following the same logic as in the one-duck case. That is, $\\mathbf{e}_{(5,5)}^\\mathsf{T} (P\\otimes P) \\mathbf{q} + 1$.<\/p>\n<h3>A cautionary note<\/h3>\n<p>While it may seem like this is straightforward algebra, there is a major issue I neglected to discuss: invertibility. When we solve the equation for $\\mathbf{q}$ in the one-duck case, the equation looks like $A\\mathbf{q} = \\mathbf{t}$, and the solution is $\\mathbf{q} = A^{-1}\\mathbf{t}$. But what if $A$ isn&#8217;t invertible? This corresponds to cases where the Markov chain is not connected. So if you start on one island and the terminal set is on another island, you&#8217;ll never get there; the stopping time is infinite. That doesn&#8217;t happen with one duck, but it <e>does<\/e> happen with two ducks! This is because every time a duck moves to a new stone, the parity of the stone changes from odd to even or vice versa. So if one duck started on rock 1 and the other started on rock 2, they would <em>never<\/em> meet.<\/p>\n<p>From a linear algebra standpoint, it just means that even though the matrix is not invertible, if we restrict our attention to the &#8220;island&#8221; (read: subspace) where the two ducks have the same parity, then the associated transition matrix for that island will be invertible and everything will be fine. From a practical standpoint, the equation above can still be solved; we just need to replace the inverse by a <a href=\"https:\/\/en.wikipedia.org\/wiki\/Moore%E2%80%93Penrose_inverse\">pseudoinverse<\/a>, and ignore all the components of $\\mathbf{q}$ for which the two components have different parity. More on this later&#8230;<\/p>\n<h3>Computation<\/h3>\n<p>I computed the result using the following Matlab code:<\/p>\n<pre>\r\n% transition matrix for one duck\r\nP = [ 0 1\/2 0 1\/2 0  0  0  0  0\r\n     1\/3 0 1\/3 0 1\/3 0  0  0  0\r\n      0 1\/2 0  0  0 1\/2 0  0  0\r\n     1\/3 0  0  0 1\/3 0 1\/3 0  0\r\n      0 1\/4 0 1\/4 0 1\/4 0 1\/4 0\r\n      0  0 1\/3 0 1\/3 0  0  0 1\/3\r\n      0  0  0 1\/2 0  0  0 1\/2 0\r\n      0  0  0  0 1\/3 0 1\/3 0 1\/3\r\n      0  0  0  0  0 1\/2 0 1\/2 0 ];\r\n\r\nT = kron(P,P);     % transition matrix\r\nt = 1-vec(eye(9)); % terminal states\r\n\r\n% starting distribution\r\ns = kron([0 0 0 0 1 0 0 0 0],[0 0 0 0 1 0 0 0 0])';\r\n\r\n% compute stopping time as a rational number\r\nstop_time = s'*T*( (eye(81)-diag(t)*T)\\t ) + 1\r\nrats(stop_time)\r\n<\/pre>\n<p>The resulting expected stopping time was $\\frac{363}{74}$, or approximately $4.905$ steps. We can also find an approximate answer via simulation. Here is what you get by simulating one million trials:<\/p>\n<p><a href=\"https:\/\/laurentlessard.com\/bookproofs\/wp-content\/uploads\/2020\/01\/delirious_ducks2.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/laurentlessard.com\/bookproofs\/wp-content\/uploads\/2020\/01\/delirious_ducks2-1024x728.png\" alt=\"\" width=\"840\" height=\"597\" class=\"aligncenter size-large wp-image-2757\" srcset=\"https:\/\/laurentlessard.com\/bookproofs\/wp-content\/uploads\/2020\/01\/delirious_ducks2-1024x728.png 1024w, https:\/\/laurentlessard.com\/bookproofs\/wp-content\/uploads\/2020\/01\/delirious_ducks2-300x213.png 300w, https:\/\/laurentlessard.com\/bookproofs\/wp-content\/uploads\/2020\/01\/delirious_ducks2-768x546.png 768w, https:\/\/laurentlessard.com\/bookproofs\/wp-content\/uploads\/2020\/01\/delirious_ducks2-1200x854.png 1200w, https:\/\/laurentlessard.com\/bookproofs\/wp-content\/uploads\/2020\/01\/delirious_ducks2.png 1348w\" sizes=\"auto, (max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 1362px) 62vw, 840px\" \/><\/a><\/p>\n<p>The staggered decrease of the probabilities is a real effect; it&#8217;s not a result of approximation error!<\/p>\n<h3>Many ducks<\/h3>\n<p>If we have $n$ ducks, we can clearly just generalize the approach used above. This time, the transition matrix will be $\\underbrace{P\\otimes \\cdots \\otimes P}_{n\\text{ times}}$. The issue here is that our transition matrix will be quite large: $9^n \\times 9^n$, to be precise. One way to shrink the number of states is to return to the idea of parity. The reason our transition matrix is large is because it describes <em>all<\/em> transitions between all possible duck configurations. Since we know all ducks start on the same node and that parity will be preserved, we only need to worry about the subset of states for which all ducks have the same parity. Namely, there will be $5^n$ odd states and $4^n$ even states. So we can restrict ourselves to a smaller $(5^n+4^n)\\times(5^n+4^n)$ transition matrix. This is still large, but it&#8217;s an improvement. We will also leverage the fact that the transition matrix will be sparse, which will help with computation.<\/p>\n<p>After all this work, we end up with the following result (for up to 6 ducks):<\/p>\n<p><a href=\"https:\/\/laurentlessard.com\/bookproofs\/wp-content\/uploads\/2020\/01\/delirious_ducks3.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/laurentlessard.com\/bookproofs\/wp-content\/uploads\/2020\/01\/delirious_ducks3-1024x562.png\" alt=\"\" width=\"840\" height=\"461\" class=\"aligncenter size-large wp-image-2756\" srcset=\"https:\/\/laurentlessard.com\/bookproofs\/wp-content\/uploads\/2020\/01\/delirious_ducks3-1024x562.png 1024w, https:\/\/laurentlessard.com\/bookproofs\/wp-content\/uploads\/2020\/01\/delirious_ducks3-300x165.png 300w, https:\/\/laurentlessard.com\/bookproofs\/wp-content\/uploads\/2020\/01\/delirious_ducks3-768x422.png 768w, https:\/\/laurentlessard.com\/bookproofs\/wp-content\/uploads\/2020\/01\/delirious_ducks3-1200x659.png 1200w, https:\/\/laurentlessard.com\/bookproofs\/wp-content\/uploads\/2020\/01\/delirious_ducks3.png 1227w\" sizes=\"auto, (max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 1362px) 62vw, 840px\" \/><\/a><\/p>\n<p>The values are as follows:<\/p>\n<table>\n<tr>\n<th>Number of ducks<\/th>\n<th>Expected rendez-vous time<\/th>\n<\/tr>\n<tr>\n<td>2<\/td>\n<td>4.9054<\/td>\n<\/tr>\n<tr>\n<td>3<\/td>\n<td>18.4360<\/td>\n<\/tr>\n<tr>\n<td>4<\/td>\n<td>66.7420<\/td>\n<\/tr>\n<tr>\n<td>5<\/td>\n<td>237.3955<\/td>\n<\/tr>\n<tr>\n<td>6<\/td>\n<td>825.3364<\/td>\n<\/tr>\n<\/table>\n<p>It&#8217;s clear the expected rendez-vous time grows exponentially, but I haven&#8217;t found a practical way to approximate it or bound it. Unfortunately, it&#8217;s pretty difficult to extend my approach beyond $n=6$ ducks. To give you an idea of scale, our naive transition matrix would have had $9^6=531,441$ rows and columns. After our reduction procedure, we&#8217;re down to $5^6+4^6=19,721$. The transition matrix is sparse (about 98.5% of its entries are zeros), but that still leaves about 6 million nonzero entries, which makes computing $\\mathbf{q}$ a challenge.<\/p>\n<p>Further reductions are possible if we leverage symmetries. Let&#8217;s say we have 2 ducks. If we don&#8217;t do any reductions, there are $9^2=81$ states. If we reduce using even\/odd parity, we  drop to $5^2+4^2 = 41$.<\/p>\n<ul>\n<li> From a stopping time standpoint, the only thing that matters is how many ducks are on each stone; it doesn&#8217;t matter which ducks are on which stones. This immediately allows us to reduce $5^n+4^n$ to ${n+4 \\choose 4} + {n+3\\choose 3}$, which is a dramatic improvement. In the two-duck case, this brings us to $25$.\n<li> Deeper symmetries occur as well. For example, a pair of ducks on 1 and 3 is equivalent to a pair of ducks on 7 and 9 by rotational symmetry. In the two-duck case, this brings us to $8$ states. Counting and bookkeeping these states might require some <a href=\"https:\/\/en.wikipedia.org\/wiki\/Group_theory\">group theory<\/a>&#8230;\n<\/ul>\n<p>Ultimately, these reductions would have a dramatic effect, reducing the scaling from exponential to polynomial. I didn&#8217;t implement any of these additional reductions because at this point (up to $n=6$) the exponential trend was clear. I didn&#8217;t think that extending the trend further would be particularly enlightening.\n<\/p><\/div>\n","protected":false},"excerpt":{"rendered":"<p>This week&#8217;s Riddler Classic is about random walks on a lattice: Two delirious ducks are having a difficult time finding each other in their pond. The pond happens to contain a 3\u00d73 grid of rocks. Every minute, each duck randomly swims, independently of the other duck, from one rock to a neighboring rock in the &hellip; <a href=\"https:\/\/laurentlessard.com\/bookproofs\/delirious-ducks\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Delirious ducks&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"_uf_show_specific_survey":0,"_uf_disable_surveys":false,"footnotes":""},"categories":[7],"tags":[20,8,21,2],"class_list":["post-2739","post","type-post","status-publish","format-standard","hentry","category-riddler","tag-markov-chains","tag-probability","tag-random-walk","tag-riddler"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/laurentlessard.com\/bookproofs\/wp-json\/wp\/v2\/posts\/2739","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/laurentlessard.com\/bookproofs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/laurentlessard.com\/bookproofs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/laurentlessard.com\/bookproofs\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/laurentlessard.com\/bookproofs\/wp-json\/wp\/v2\/comments?post=2739"}],"version-history":[{"count":22,"href":"https:\/\/laurentlessard.com\/bookproofs\/wp-json\/wp\/v2\/posts\/2739\/revisions"}],"predecessor-version":[{"id":2767,"href":"https:\/\/laurentlessard.com\/bookproofs\/wp-json\/wp\/v2\/posts\/2739\/revisions\/2767"}],"wp:attachment":[{"href":"https:\/\/laurentlessard.com\/bookproofs\/wp-json\/wp\/v2\/media?parent=2739"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/laurentlessard.com\/bookproofs\/wp-json\/wp\/v2\/categories?post=2739"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/laurentlessard.com\/bookproofs\/wp-json\/wp\/v2\/tags?post=2739"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}