<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Claudio Contardo</title>
	<atom:link href="http://claudio.contardo.org/feed/" rel="self" type="application/rss+xml" />
	<link>http://claudio.contardo.org</link>
	<description>My academic website</description>
	<lastBuildDate>Mon, 30 Apr 2012 15:44:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>The 3-5-7 sticks game (a.k.a. Nim)</title>
		<link>http://claudio.contardo.org/2011/06/sticks-game/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=sticks-game</link>
		<comments>http://claudio.contardo.org/2011/06/sticks-game/#comments</comments>
		<pubDate>Mon, 27 Jun 2011 22:24:45 +0000</pubDate>
		<dc:creator>ccontard</dc:creator>
				<category><![CDATA[Games]]></category>
		<category><![CDATA[dynamic-programming]]></category>
		<category><![CDATA[games]]></category>
		<category><![CDATA[nim]]></category>

		<guid isPermaLink="false">http://claudio.contardo.org/?p=1</guid>
		<description><![CDATA[I remember a long time ago, in the chilean TV, an interactive game played by telephone between a &#8220;magician&#8221; and a spectator. The game itself was pretty simple. Given an initial configuration of 15 sticks, like in the figure below, both players can erase from any of the rows as many sticks as they want &#8230; <a href="http://claudio.contardo.org/2011/06/sticks-game/">Continue reading <span class="meta-nav">&#187;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I remember a long time ago, in the chilean TV, an interactive game played by telephone between a &#8220;magician&#8221; and a spectator. The game itself was pretty simple. Given an initial configuration of 15 sticks, like in the figure below, both players can erase from any of the rows as many sticks as they want (but always from the same row). The winner is the one which makes the opponent take the last stick.</p>
<p style="text-align: center;"><img class="aligncenter" title="sticks" src="http://claudio.contardo.org/wp-content/uploads/2011/06/sticks-300x208.jpg" alt="" width="180" height="125" /></p>
<p>Each week, the game was repeated with different opponents and the total prize was also accumulating. At the end, the prize for the winner was something like some thousands of dollars. Now, I would like to share with you the resolution of this apparently difficult problem. Indeed, I will show to you that there exists a winning strategy for the starting player. Formally, let us define a configuration as</p>
<p style="text-align: center;"><img src='http://s0.wp.com/latex.php?latex=%5Cmathcal%7BC%7D+%3D+%28i%2C+j%2C+k%29%5Cqquad+i%5Cleq+j%5Cleq+k&#038;bg=ffffff&#038;fg=333333&#038;s=0' alt='&#92;mathcal{C} = (i, j, k)&#92;qquad i&#92;leq j&#92;leq k' title='&#92;mathcal{C} = (i, j, k)&#92;qquad i&#92;leq j&#92;leq k' class='latex' /></p>
<p style="text-align: left;">where <em>i</em>, <em>j</em>, <em>k</em> represent the number of sticks at each row. Note that the swapping of two rows produces an equivalent solution and therefore the supposition that <em>i</em> ≤ <em>j</em> ≤ <em>k</em> is without loss of generality, We will say that a configuration <em>C2</em> is obtained by <em>C1</em> if there exists a valid movement (stick removal) from configuration <em>C1</em> that produces <em>C2</em>. If we denote that movement by <em>m</em>, we will denote this transition by</p>
<p style="text-align: center;"><img src='http://s0.wp.com/latex.php?latex=%5Cmathcal%7BC%7D_2+%3D+T%28%5Cmathcal%7BC%7D_1%2C+m%29&#038;bg=ffffff&#038;fg=333333&#038;s=0' alt='&#92;mathcal{C}_2 = T(&#92;mathcal{C}_1, m)' title='&#92;mathcal{C}_2 = T(&#92;mathcal{C}_1, m)' class='latex' /></p>
<p style="text-align: left;">Now, for a configuration <em>W</em> we say that <em>W</em> is a <em>winning configuration</em> if there exists a movement <em>m</em> from <em>W</em> that produces another configuration <em>L</em> and such that every possible moment <em>m&#8217;</em> from <em>L</em> produces another winning configuration <em>W&#8217;</em>. Formally, for every state <em>C</em> we define a binary value <em>w(C)</em> as follows</p>
<p style="text-align: center;"><img src='http://s0.wp.com/latex.php?latex=w%28+%5Cmathcal%7BC%7D+%29+%3D+%5Cbigvee_%7Bm%7D%5Cbigwedge_%7Bm%27%7Dw%28T%28T%28%5Cmathcal%7BC%7D%2C+m%29%2C+m%27%29%29&#038;bg=ffffff&#038;fg=333333&#038;s=0' alt='w( &#92;mathcal{C} ) = &#92;bigvee_{m}&#92;bigwedge_{m&#039;}w(T(T(&#92;mathcal{C}, m), m&#039;))' title='w( &#92;mathcal{C} ) = &#92;bigvee_{m}&#92;bigwedge_{m&#039;}w(T(T(&#92;mathcal{C}, m), m&#039;))' class='latex' /></p>
<p style="text-align: left;">It suffices to define the two base cases <em>w(0, 0, 0) = true</em> and <em>w(0, 0, 1) = false</em> and the remaining winning configurations can be recovered from these two configurations. This problem can be solved by dynamic programming in a fraction of a second. In the following table, I put the winning configurations <em>W</em> and their respective winning moves <em>m</em>. A move is represented by a pair <em>(r, k)</em> where <em>r</em> is the row index (1, 2 or 3) and <em>k</em> is the number of sticks to remove from it. Note that <em>(3, 5, 7)</em> is a winning configuration and so the starting player has a winning strategy.</p>
<table border="1">
<thead>
<tr>
<td><span style="font-weight: bold;"><em>W</em></span></td>
<td><span style="font-weight: bold;"><em>m</em></span></td>
<td><span style="font-weight: bold;"><em>W</em></span></td>
<td><span style="font-weight: bold;"><em>m</em></span></td>
<td><span style="font-weight: bold;"><em>W</em></span></td>
<td><span style="font-weight: bold;"><em>m</em></span></td>
</tr>
</thead>
<tbody>
<tr>
<td>(0, 0, 2)</td>
<td>(3, 1)</td>
<td>(0, 1, 1)</td>
<td>(2, 1)</td>
<td>(0, 0, 3)</td>
<td>(3, 2)</td>
</tr>
<tr>
<td>(0, 1, 2)</td>
<td>(3, 2)</td>
<td>(0, 0, 4)</td>
<td>(3, 3)</td>
<td>(0, 1, 3)</td>
<td>(3, 3)</td>
</tr>
<tr>
<td>(1, 1, 2)</td>
<td>(3, 1)</td>
<td>(0, 0, 5)</td>
<td>(3, 4)</td>
<td>(0, 1, 4)</td>
<td>(3, 4)</td>
</tr>
<tr>
<td>(0, 2, 3)</td>
<td>(3, 1)</td>
<td>(1, 1, 3)</td>
<td>(3, 2)</td>
<td>(1, 2, 2)</td>
<td>(1, 1)</td>
</tr>
<tr>
<td>(0, 0, 6)</td>
<td>(3, 5)</td>
<td>(0, 1, 5)</td>
<td>(3, 5)</td>
<td>(0, 2, 4)</td>
<td>(3, 2)</td>
</tr>
<tr>
<td>(1, 1, 4)</td>
<td>(3, 3)</td>
<td>(2, 2, 2)</td>
<td>(1, 2)</td>
<td>(0, 0, 7)</td>
<td>(3, 6)</td>
</tr>
<tr>
<td>(0, 1, 6)</td>
<td>(3, 6)</td>
<td>(0, 2, 5)</td>
<td>(3, 3)</td>
<td>(0, 3, 4)</td>
<td>(3, 1)</td>
</tr>
<tr>
<td>(1, 1, 5)</td>
<td>(3, 4)</td>
<td>(1, 2, 4)</td>
<td>(3, 1)</td>
<td>(1, 3, 3)</td>
<td>(1, 1)</td>
</tr>
<tr>
<td>(2, 2, 3)</td>
<td>(1, 1)</td>
<td>(0, 1, 7)</td>
<td>(3, 7)</td>
<td>(0, 2, 6)</td>
<td>(3, 4)</td>
</tr>
<tr>
<td>(0, 3, 5)</td>
<td>(3, 2)</td>
<td>(1, 1, 6)</td>
<td>(3, 5)</td>
<td>(1, 2, 5)</td>
<td>(3, 2)</td>
</tr>
<tr>
<td>(1, 3, 4)</td>
<td>(3, 2)</td>
<td>(2, 2, 4)</td>
<td>(3, 4)</td>
<td>(2, 3, 3)</td>
<td>(1, 2)</td>
</tr>
<tr>
<td>(0, 2, 7)</td>
<td>(3, 5)</td>
<td>(0, 3, 6)</td>
<td>(3, 3)</td>
<td>(0, 4, 5)</td>
<td>(3, 1)</td>
</tr>
<tr>
<td>(1, 1, 7)</td>
<td>(3, 6)</td>
<td>(1, 2, 6)</td>
<td>(3, 3)</td>
<td>(1, 3, 5)</td>
<td>(3, 3)</td>
</tr>
<tr>
<td>(1, 4, 4)</td>
<td>(1, 1)</td>
<td>(2, 2, 5)</td>
<td>(3, 5)</td>
<td>(2, 3, 4)</td>
<td>(3, 3)</td>
</tr>
<tr>
<td>(3, 3, 3)</td>
<td>(1, 3)</td>
<td>(0, 3, 7)</td>
<td>(3, 4)</td>
<td>(0, 4, 6)</td>
<td>(3, 2)</td>
</tr>
<tr>
<td>(1, 2, 7)</td>
<td>(3, 4)</td>
<td>(1, 3, 6)</td>
<td>(3, 4)</td>
<td>(2, 2, 6)</td>
<td>(3, 6)</td>
</tr>
<tr>
<td>(2, 3, 5)</td>
<td>(3, 4)</td>
<td>(2, 4, 4)</td>
<td>(1, 2)</td>
<td>(3, 3, 4)</td>
<td>(3, 4)</td>
</tr>
<tr>
<td>(0, 4, 7)</td>
<td>(3, 3)</td>
<td>(0, 5, 6)</td>
<td>(3, 1)</td>
<td>(1, 3, 7)</td>
<td>(3, 5)</td>
</tr>
<tr>
<td>(1, 4, 6)</td>
<td>(3, 1)</td>
<td>(1, 5, 5)</td>
<td>(1, 1)</td>
<td>(2, 2, 7)</td>
<td>(3, 7)</td>
</tr>
<tr>
<td>(2, 3, 6)</td>
<td>(3, 5)</td>
<td>(2, 4, 5)</td>
<td>(1, 1)</td>
<td>(3, 3, 5)</td>
<td>(3, 5)</td>
</tr>
<tr>
<td>(3, 4, 4)</td>
<td>(1, 3)</td>
<td>(0, 5, 7)</td>
<td>(3, 2)</td>
<td>(1, 4, 7)</td>
<td>(3, 2)</td>
</tr>
<tr>
<td>(1, 5, 6)</td>
<td>(3, 2)</td>
<td>(2, 3, 7)</td>
<td>(3, 6)</td>
<td>(2, 5, 5)</td>
<td>(1, 2)</td>
</tr>
<tr>
<td>(3, 3, 6)</td>
<td>(3, 6)</td>
<td>(3, 4, 5)</td>
<td>(1, 2)</td>
<td>(1, 5, 7)</td>
<td>(3, 3)</td>
</tr>
<tr>
<td>(2, 4, 7)</td>
<td>(3, 1)</td>
<td>(2, 5, 6)</td>
<td>(2, 1)</td>
<td>(3, 3, 7)</td>
<td>(3, 7)</td>
</tr>
<tr>
<td>(3, 4, 6)</td>
<td>(1, 1)</td>
<td>(3, 5, 5)</td>
<td>(1, 3)</td>
<td>(3, 5, 7)</td>
<td>(1, 1)</td>
</tr>
</tbody>
</table>
]]></content:encoded>
			<wfw:commentRss>http://claudio.contardo.org/2011/06/sticks-game/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

