<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: Puzzler: Coin game</title>
	<atom:link href="http://blogs.mathworks.com/videos/2008/03/31/puzzler-coin-game/feed/" rel="self" type="application/rss+xml" />
	<link>http://blogs.mathworks.com/videos/2008/03/31/puzzler-coin-game/</link>
	<description>Doug Hull is a proud MathWorker who is on a mission to help you with MATLAB.</description>
	<lastBuildDate>Fri, 10 Feb 2012 18:02:11 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
	<item>
		<title>By: Sam Roberts</title>
		<link>http://blogs.mathworks.com/videos/2008/03/31/puzzler-coin-game/#comment-1352</link>
		<dc:creator>Sam Roberts</dc:creator>
		<pubDate>Wed, 04 Mar 2009 16:29:27 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/videos/2008/03/31/puzzler-coin-game/#comment-1352</guid>
		<description>A recursive solution:

function probs = myprob(turns)

probabilityMatrix =...
[ 1/4 1/2 1/4 0;...
1/4 0 1/2 1/4; ...
1/2 0 0 1/2; ...
3/4 1/4 0 0];

if turns == 0
    probs = [1,0,0,0];
else
    probs = myprob(turns-1)*probabilityMatrix;
end

Sam</description>
		<content:encoded><![CDATA[<p>A recursive solution:</p>
<p>function probs = myprob(turns)</p>
<p>probabilityMatrix =&#8230;<br />
[ 1/4 1/2 1/4 0;...<br />
1/4 0 1/2 1/4; ...<br />
1/2 0 0 1/2; ...<br />
3/4 1/4 0 0];</p>
<p>if turns == 0<br />
    probs = [1,0,0,0];<br />
else<br />
    probs = myprob(turns-1)*probabilityMatrix;<br />
end</p>
<p>Sam</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: craig</title>
		<link>http://blogs.mathworks.com/videos/2008/03/31/puzzler-coin-game/#comment-906</link>
		<dc:creator>craig</dc:creator>
		<pubDate>Tue, 19 Aug 2008 05:46:32 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/videos/2008/03/31/puzzler-coin-game/#comment-906</guid>
		<description>Output: x

p = [.25 .25 .5 .75 ; .5 0 0 .25 ; .25 .5 0 0 ; 0 .25 .5 0 ];
[P D] = eig(p);
D=(abs(D)&gt;.99).*D;
x = real(P * D * P^(-1) * [1 ; 0 ; 0 ; 0]);

The idea here is to use the eigenvalue decomposition, noting that the eigenvalues with norm less than 1 will vanish.  Remove those eigenvalues and reassemble the matrix.  Multiply by the starting vector and you have the result.  This is accurate to machine precision.  The real is to remove the roundoff imaginary components.</description>
		<content:encoded><![CDATA[<p>Output: x</p>
<p>p = [.25 .25 .5 .75 ; .5 0 0 .25 ; .25 .5 0 0 ; 0 .25 .5 0 ];<br />
[P D] = eig(p);<br />
D=(abs(D)&gt;.99).*D;<br />
x = real(P * D * P^(-1) * [1 ; 0 ; 0 ; 0]);</p>
<p>The idea here is to use the eigenvalue decomposition, noting that the eigenvalues with norm less than 1 will vanish.  Remove those eigenvalues and reassemble the matrix.  Multiply by the starting vector and you have the result.  This is accurate to machine precision.  The real is to remove the roundoff imaginary components.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Urs (us) Schwarz</title>
		<link>http://blogs.mathworks.com/videos/2008/03/31/puzzler-coin-game/#comment-899</link>
		<dc:creator>Urs (us) Schwarz</dc:creator>
		<pubDate>Tue, 01 Apr 2008 16:25:58 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/videos/2008/03/31/puzzler-coin-game/#comment-899</guid>
		<description>as with last weeks puzzler, when i had to second guess the task from a few examples (with consecutive bad proposals, of course), i&#039;m again NOT able to run the videos from behind our two firewalls (the flash player [9,0,115,0] works fine, though, for other stuff): it shows about one 3rd of the first and kills the browser for the second...
it&#039;s just a bit frustrating...

best from zurich
urs

ps: maybe i&#039;m not meant to contribute... or it&#039;s just the date...</description>
		<content:encoded><![CDATA[<p>as with last weeks puzzler, when i had to second guess the task from a few examples (with consecutive bad proposals, of course), i&#8217;m again NOT able to run the videos from behind our two firewalls (the flash player [9,0,115,0] works fine, though, for other stuff): it shows about one 3rd of the first and kills the browser for the second&#8230;<br />
it&#8217;s just a bit frustrating&#8230;</p>
<p>best from zurich<br />
urs</p>
<p>ps: maybe i&#8217;m not meant to contribute&#8230; or it&#8217;s just the date&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Doug</title>
		<link>http://blogs.mathworks.com/videos/2008/03/31/puzzler-coin-game/#comment-898</link>
		<dc:creator>Doug</dc:creator>
		<pubDate>Tue, 01 Apr 2008 15:17:42 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/videos/2008/03/31/puzzler-coin-game/#comment-898</guid>
		<description>Daniel,

About the comments.  Great idea.  I will make it a best practice.

Thanks,
Doug</description>
		<content:encoded><![CDATA[<p>Daniel,</p>
<p>About the comments.  Great idea.  I will make it a best practice.</p>
<p>Thanks,<br />
Doug</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Doug</title>
		<link>http://blogs.mathworks.com/videos/2008/03/31/puzzler-coin-game/#comment-897</link>
		<dc:creator>Doug</dc:creator>
		<pubDate>Tue, 01 Apr 2008 15:17:12 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/videos/2008/03/31/puzzler-coin-game/#comment-897</guid>
		<description>Daniel, Richard

I am surprised that so many people jumped no the Markov chain method, I expected that the exhaustive search or monte carlo methods would dominate.  Maybe that is because I worked with distributed computing clusters for MATLAB for a while but never really studied Markov Chains.

Thanks for playing!
Doug</description>
		<content:encoded><![CDATA[<p>Daniel, Richard</p>
<p>I am surprised that so many people jumped no the Markov chain method, I expected that the exhaustive search or monte carlo methods would dominate.  Maybe that is because I worked with distributed computing clusters for MATLAB for a while but never really studied Markov Chains.</p>
<p>Thanks for playing!<br />
Doug</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Doug</title>
		<link>http://blogs.mathworks.com/videos/2008/03/31/puzzler-coin-game/#comment-896</link>
		<dc:creator>Doug</dc:creator>
		<pubDate>Tue, 01 Apr 2008 15:11:35 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/videos/2008/03/31/puzzler-coin-game/#comment-896</guid>
		<description>Francois,

A beautiful solution.  I like how you derived the M matrix rather than it being a &quot;Magic Number Matrix&quot; (which is what I did).

When I was designing this challenge, I was going to have an add-on where the number of coins and number of squares was variable.  I thought that simpler was better.  I see that your code would have been able to handle such a complication nicely.

Thanks for a great solution that works in a different way than the earlier one.

Doug</description>
		<content:encoded><![CDATA[<p>Francois,</p>
<p>A beautiful solution.  I like how you derived the M matrix rather than it being a &#8220;Magic Number Matrix&#8221; (which is what I did).</p>
<p>When I was designing this challenge, I was going to have an add-on where the number of coins and number of squares was variable.  I thought that simpler was better.  I see that your code would have been able to handle such a complication nicely.</p>
<p>Thanks for a great solution that works in a different way than the earlier one.</p>
<p>Doug</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Daniel Armyr</title>
		<link>http://blogs.mathworks.com/videos/2008/03/31/puzzler-coin-game/#comment-905</link>
		<dc:creator>Daniel Armyr</dc:creator>
		<pubDate>Tue, 01 Apr 2008 09:06:29 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/videos/2008/03/31/puzzler-coin-game/#comment-905</guid>
		<description>Hi.
One general comment about how you write your blog. I noticed that Loren allways puts a link to the comments section in the text of her entries. I read these blogs with a feed reader so I don&#039;t get the automatic footer with links to the comments section as I get when I visit the homepage. If there is a link in the text, I can go directly to the comments section which is nice.

Sincerely
Daniel Armyr</description>
		<content:encoded><![CDATA[<p>Hi.<br />
One general comment about how you write your blog. I noticed that Loren allways puts a link to the comments section in the text of her entries. I read these blogs with a feed reader so I don&#8217;t get the automatic footer with links to the comments section as I get when I visit the homepage. If there is a link in the text, I can go directly to the comments section which is nice.</p>
<p>Sincerely<br />
Daniel Armyr</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Daniel Armyr</title>
		<link>http://blogs.mathworks.com/videos/2008/03/31/puzzler-coin-game/#comment-904</link>
		<dc:creator>Daniel Armyr</dc:creator>
		<pubDate>Tue, 01 Apr 2008 07:22:27 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/videos/2008/03/31/puzzler-coin-game/#comment-904</guid>
		<description>Yeah, the markov chain is of couse the obvious method here, assuming you are familiar with statistics. Richard here beat me to it though. My solution is identical to his, although quite a bit more verbose:

startPos = [1; 0; 0; 0];
numberOfMoves = 20;

probabilityMatrix = ...
    [ 1/4 1/2 1/4 0; ...
    1/4 0 1/2 1/4; ...
    1/2 0 0 1/2; ...
    3/4 1/4 0 0]&#039;;

probabilityAfter20Turns = probabilityMatrix^numberOfMoves*startPos</description>
		<content:encoded><![CDATA[<p>Yeah, the markov chain is of couse the obvious method here, assuming you are familiar with statistics. Richard here beat me to it though. My solution is identical to his, although quite a bit more verbose:</p>
<p>startPos = [1; 0; 0; 0];<br />
numberOfMoves = 20;</p>
<p>probabilityMatrix = &#8230;<br />
    [ 1/4 1/2 1/4 0; ...<br />
    1/4 0 1/2 1/4; ...<br />
    1/2 0 0 1/2; ...<br />
    3/4 1/4 0 0]&#8216;;</p>
<p>probabilityAfter20Turns = probabilityMatrix^numberOfMoves*startPos</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Richard Brown</title>
		<link>http://blogs.mathworks.com/videos/2008/03/31/puzzler-coin-game/#comment-903</link>
		<dc:creator>Richard Brown</dc:creator>
		<pubDate>Mon, 31 Mar 2008 21:30:41 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/videos/2008/03/31/puzzler-coin-game/#comment-903</guid>
		<description>Alternatively, as a finite time-homogeneous Markov chain

p20 = (0.25 * [1 2 1 0; 1 0 2 1; 2 0 0 2; 3 1 0 0])^20;
disp(p20(1, :))

cheers,

Richard</description>
		<content:encoded><![CDATA[<p>Alternatively, as a finite time-homogeneous Markov chain</p>
<p>p20 = (0.25 * [1 2 1 0; 1 0 2 1; 2 0 0 2; 3 1 0 0])^20;<br />
disp(p20(1, :))</p>
<p>cheers,</p>
<p>Richard</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Francois</title>
		<link>http://blogs.mathworks.com/videos/2008/03/31/puzzler-coin-game/#comment-902</link>
		<dc:creator>Francois</dc:creator>
		<pubDate>Mon, 31 Mar 2008 21:03:17 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/videos/2008/03/31/puzzler-coin-game/#comment-902</guid>
		<description>Hello Doug,

Here is a function working for a slightly more general situation:

&lt;pre&gt;
function probs = game(steps)
N = 4; % number of game states

% Basic transition matrices
% move(k) corresponds to &quot;move k squares&quot;
move = @(k)circshift(eye(N),[0 k]);
% go(k) corresponds to &quot;go to square k&quot;
go = @(k)ones(N,1)*((1:N)==k);

% Build the actual transition matrix
M = 1/2 * move(1) + 1/4 * move(2) + 1/4 * go(1);

% Compute probabilities
if steps &lt; inf
   % Finite number of steps: intermediate distributions are computed
   % using successive matrix-vector products
   state = (1:N)==1;
   for i = 1:steps
       state = state*M;
       probs(i, 1:N) = state;
   end
else
   % Infinite number of steps: stationary distribution is computed
   % (assuming it exists) by solving a linear system
   probs = [zeros(1,N) 1] /[M-eye(N) ones(N,1)];
end
&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>Hello Doug,</p>
<p>Here is a function working for a slightly more general situation:</p>
<pre>
function probs = game(steps)
N = 4; % number of game states

% Basic transition matrices
% move(k) corresponds to "move k squares"
move = @(k)circshift(eye(N),[0 k]);
% go(k) corresponds to "go to square k"
go = @(k)ones(N,1)*((1:N)==k);

% Build the actual transition matrix
M = 1/2 * move(1) + 1/4 * move(2) + 1/4 * go(1);

% Compute probabilities
if steps &lt; inf
   % Finite number of steps: intermediate distributions are computed
   % using successive matrix-vector products
   state = (1:N)==1;
   for i = 1:steps
       state = state*M;
       probs(i, 1:N) = state;
   end
else
   % Infinite number of steps: stationary distribution is computed
   % (assuming it exists) by solving a linear system
   probs = [zeros(1,N) 1] /[M-eye(N) ones(N,1)];
end
</pre>
]]></content:encoded>
	</item>
</channel>
</rss>

