<?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"
	>
<channel>
	<title>Comments on: Google Treasure Hunt, check!</title>
	<atom:link href="http://therning.org/magnus/archives/352/feed" rel="self" type="application/rss+xml" />
	<link>http://therning.org/magnus/archives/352</link>
	<description>Incoherent mumblings</description>
	<pubDate>Fri, 05 Dec 2008 09:31:25 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6.3</generator>
		<item>
		<title>By: Magnus</title>
		<link>http://therning.org/magnus/archives/352#comment-126693</link>
		<dc:creator>Magnus</dc:creator>
		<pubDate>Wed, 11 Jun 2008 06:53:59 +0000</pubDate>
		<guid isPermaLink="false">http://therning.org/magnus/?p=352#comment-126693</guid>
		<description>&lt;p&gt;@hezekiah,&lt;/p&gt;

&lt;p&gt;I'm glad you had fun with the Treasure Hunt.&lt;/p&gt;

&lt;p&gt;I solved the first problem in exactly the same way as you did.  That's what I meant by mentioning Pascal's triangle.  Wikipedia has an excellent page on Pascal's triangle.&lt;/p&gt;

&lt;p&gt;If you still don't see it, take your grid of size MxN and in each square you put the number of paths to reach it.  Now tilt your head slightly to the left. ;-)&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>@hezekiah,</p>
<p>I&#8217;m glad you had fun with the Treasure Hunt.</p>
<p>I solved the first problem in exactly the same way as you did.  That&#8217;s what I meant by mentioning Pascal&#8217;s triangle.  Wikipedia has an excellent page on Pascal&#8217;s triangle.</p>
<p>If you still don&#8217;t see it, take your grid of size MxN and in each square you put the number of paths to reach it.  Now tilt your head slightly to the left. <img src='http://therning.org/magnus/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: hezekiah</title>
		<link>http://therning.org/magnus/archives/352#comment-126650</link>
		<dc:creator>hezekiah</dc:creator>
		<pubDate>Tue, 10 Jun 2008 21:53:19 +0000</pubDate>
		<guid isPermaLink="false">http://therning.org/magnus/?p=352#comment-126650</guid>
		<description>&lt;p&gt;Magnus: I noticed your post on Planet Haskell and found it quite interesting.  I had never heard of the Google Treasure hunt before, so I went and did the problems.  Thanks for the nice post and introducing me to the treasure hunt.&lt;/p&gt;

&lt;p&gt;Regarding the first question (involving the robot), you can actually solve it without any coding at all, only a little combinatorial math.  The problem states that the robot needs to move from the top-left corner to the bottom-right of an NxM grid.  Since he can only make moves of one square down or one square right, you can think of a path as a sequence of R and D instructions for Right and Down.  Since the robot must make N-1 moves right and M-1 moves down to reach the destination, the problem can be restated as "How many unique strings of length N+M-2 can you make out of N-1 R's and M-1 D's?"  This can be solved with a single equation: (n+m-2)!/(n-1)!(m-1)!&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Magnus: I noticed your post on Planet Haskell and found it quite interesting.  I had never heard of the Google Treasure hunt before, so I went and did the problems.  Thanks for the nice post and introducing me to the treasure hunt.</p>
<p>Regarding the first question (involving the robot), you can actually solve it without any coding at all, only a little combinatorial math.  The problem states that the robot needs to move from the top-left corner to the bottom-right of an NxM grid.  Since he can only make moves of one square down or one square right, you can think of a path as a sequence of R and D instructions for Right and Down.  Since the robot must make N-1 moves right and M-1 moves down to reach the destination, the problem can be restated as &#8220;How many unique strings of length N+M-2 can you make out of N-1 R&#8217;s and M-1 D&#8217;s?&#8221;  This can be solved with a single equation: (n+m-2)!/(n-1)!(m-1)!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Peter</title>
		<link>http://therning.org/magnus/archives/352#comment-126216</link>
		<dc:creator>Peter</dc:creator>
		<pubDate>Mon, 09 Jun 2008 00:25:36 +0000</pubDate>
		<guid isPermaLink="false">http://therning.org/magnus/?p=352#comment-126216</guid>
		<description>&lt;p&gt;Andre:&lt;/p&gt;

&lt;p&gt;I &lt;em&gt;really&lt;/em&gt; like how you did that!&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Andre:</p>
<p>I <em>really</em> like how you did that!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Andre</title>
		<link>http://therning.org/magnus/archives/352#comment-126097</link>
		<dc:creator>Andre</dc:creator>
		<pubDate>Sun, 08 Jun 2008 11:06:34 +0000</pubDate>
		<guid isPermaLink="false">http://therning.org/magnus/?p=352#comment-126097</guid>
		<description>&lt;p&gt;In most cases it's the best decision to reduce a problem to a well-known problem - the exception proves the rule. ;-)&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>In most cases it&#8217;s the best decision to reduce a problem to a well-known problem - the exception proves the rule. <img src='http://therning.org/magnus/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: therning.org/ magnus &#187; Blog Archive &#187; Google Treasure Hunt primes question</title>
		<link>http://therning.org/magnus/archives/352#comment-125986</link>
		<dc:creator>therning.org/ magnus &#187; Blog Archive &#187; Google Treasure Hunt primes question</dc:creator>
		<pubDate>Sat, 07 Jun 2008 22:58:09 +0000</pubDate>
		<guid isPermaLink="false">http://therning.org/magnus/?p=352#comment-125986</guid>
		<description>&lt;p&gt;[...] Incoherent mumblings          &#171; Google Treasure Hunt, check! [...]&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>[...] Incoherent mumblings          &laquo; Google Treasure Hunt, check! [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Magnus</title>
		<link>http://therning.org/magnus/archives/352#comment-125980</link>
		<dc:creator>Magnus</dc:creator>
		<pubDate>Sat, 07 Jun 2008 22:18:20 +0000</pubDate>
		<guid isPermaLink="false">http://therning.org/magnus/?p=352#comment-125980</guid>
		<description>&lt;p&gt;@Andre,&lt;/p&gt;

&lt;p&gt;That's a nice coding of the solution for question one.  I wonder if we had seen the same thing if we hadn't stopped looking at the shape of the numbers and instead turned to Wikipedia for the formula.&lt;/p&gt;

&lt;p&gt;I did run parts of it in GHCi during development, both to convince myself that I was doing things right and to get a feel for whether the code would find a solution during my life time ;-)  After timing the compiled code I also timed it using &lt;code&gt;runghc&lt;/code&gt; and then it took about 80 seconds.  I'll stick the code in a separate blog post later on.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>@Andre,</p>
<p>That&#8217;s a nice coding of the solution for question one.  I wonder if we had seen the same thing if we hadn&#8217;t stopped looking at the shape of the numbers and instead turned to Wikipedia for the formula.</p>
<p>I did run parts of it in GHCi during development, both to convince myself that I was doing things right and to get a feel for whether the code would find a solution during my life time <img src='http://therning.org/magnus/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' />  After timing the compiled code I also timed it using <code>runghc</code> and then it took about 80 seconds.  I&#8217;ll stick the code in a separate blog post later on.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Andre</title>
		<link>http://therning.org/magnus/archives/352#comment-125977</link>
		<dc:creator>Andre</dc:creator>
		<pubDate>Sat, 07 Jun 2008 22:05:00 +0000</pubDate>
		<guid isPermaLink="false">http://therning.org/magnus/?p=352#comment-125977</guid>
		<description>&lt;p&gt;&lt;code&gt;robot (m+1) n = last $ (iterate (scanl1 (+)) ([1] ++ replicate m 0)) !! n&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;At first the start-line (1 0 0 .. 0) is generated and thereafter the ways to each field in the lines are added from left to right. If you go down from each field you'd effectively copy the last line generated, therefore you only need one line to operate on. In fact, it results in applying the addition from left to right n times. For a 3x4-matrix it looks like this:
&lt;code&gt;1 0 0 ~&#62; 1 1 1 ~&#62; 1 2 3 ~&#62; 1 3 6 ~&#62; 1 4 10&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Regarding the primes task: I worked all the time on GHCi. Could this have caused any performance-problems? With my current implementation it takes circa 10s to find the solution. But with the sieve it'd much more elegant, hence I'm very interested in your code. :-)&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p><code>robot (m+1) n = last $ (iterate (scanl1 (+)) ([1] ++ replicate m 0)) !! n</code></p>
<p>At first the start-line (1 0 0 .. 0) is generated and thereafter the ways to each field in the lines are added from left to right. If you go down from each field you&#8217;d effectively copy the last line generated, therefore you only need one line to operate on. In fact, it results in applying the addition from left to right n times. For a 3&#215;4-matrix it looks like this:<br />
<code>1 0 0 ~&gt; 1 1 1 ~&gt; 1 2 3 ~&gt; 1 3 6 ~&gt; 1 4 10</code></p>
<p>Regarding the primes task: I worked all the time on GHCi. Could this have caused any performance-problems? With my current implementation it takes circa 10s to find the solution. But with the sieve it&#8217;d much more elegant, hence I&#8217;m very interested in your code. <img src='http://therning.org/magnus/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Magnus</title>
		<link>http://therning.org/magnus/archives/352#comment-125973</link>
		<dc:creator>Magnus</dc:creator>
		<pubDate>Sat, 07 Jun 2008 21:13:48 +0000</pubDate>
		<guid isPermaLink="false">http://therning.org/magnus/?p=352#comment-125973</guid>
		<description>&lt;p&gt;@Andre,&lt;/p&gt;

&lt;p&gt;Well, I guess my colleague and I used “verbal dynamic programming” to find Pascal's triangle in the first question :-)  Would you mind posting your Haskell one-liner somewhere and let me know?&lt;/p&gt;

&lt;p&gt;On the primes task I did use the Sieve of Eratosthenes, generating a lazy infinate list of primes.  Then passing it four times through a function to generate the sums, resulting in four more lazy infinate lists.  Then finally taking the intersection of all five lists.  The resulting compiled executable only takes about 5-8 seconds to run, depending on the question parameters.  I'll post my code here, if you want to see it.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>@Andre,</p>
<p>Well, I guess my colleague and I used “verbal dynamic programming” to find Pascal&#8217;s triangle in the first question <img src='http://therning.org/magnus/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />  Would you mind posting your Haskell one-liner somewhere and let me know?</p>
<p>On the primes task I did use the Sieve of Eratosthenes, generating a lazy infinate list of primes.  Then passing it four times through a function to generate the sums, resulting in four more lazy infinate lists.  Then finally taking the intersection of all five lists.  The resulting compiled executable only takes about 5-8 seconds to run, depending on the question parameters.  I&#8217;ll post my code here, if you want to see it.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Andre</title>
		<link>http://therning.org/magnus/archives/352#comment-125946</link>
		<dc:creator>Andre</dc:creator>
		<pubDate>Sat, 07 Jun 2008 13:26:29 +0000</pubDate>
		<guid isPermaLink="false">http://therning.org/magnus/?p=352#comment-125946</guid>
		<description>&lt;p&gt;The first question was fairly simple if you know how to apply dynamic programming to that problem. With some further thoughts I solved it in one line of Haskell-code.&lt;/p&gt;

&lt;p&gt;Also the second one was not a problem at all, which I solved mainly with System.Directory and Data.List.&lt;/p&gt;

&lt;p&gt;Due to some understanding-problems of the terminology used in the network-task, it took me some tries to figure out, how to interpret the terminology. Thereafter the task was solved easily - and without any code. ;-)&lt;/p&gt;

&lt;p&gt;The biggest problems occured in the primes-task. At first I tried to generate the primes with the Sieve of Eratosthenes. But the primes were getting too big to be generated efficiently by the sieve. Therefore I downloaded a list with the first million primes. I also wrote a function for summing up n primes and one for finding the intersection of the four infinite lists (one infinite list for each number of summands). The bottleneck in these functions was their laziness.&lt;/p&gt;

&lt;p&gt;All in all, it was really nice to see how easily these problems could be solved with Haskell. :-)&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>The first question was fairly simple if you know how to apply dynamic programming to that problem. With some further thoughts I solved it in one line of Haskell-code.</p>
<p>Also the second one was not a problem at all, which I solved mainly with System.Directory and Data.List.</p>
<p>Due to some understanding-problems of the terminology used in the network-task, it took me some tries to figure out, how to interpret the terminology. Thereafter the task was solved easily - and without any code. <img src='http://therning.org/magnus/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<p>The biggest problems occured in the primes-task. At first I tried to generate the primes with the Sieve of Eratosthenes. But the primes were getting too big to be generated efficiently by the sieve. Therefore I downloaded a list with the first million primes. I also wrote a function for summing up n primes and one for finding the intersection of the four infinite lists (one infinite list for each number of summands). The bottleneck in these functions was their laziness.</p>
<p>All in all, it was really nice to see how easily these problems could be solved with Haskell. <img src='http://therning.org/magnus/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Magnus</title>
		<link>http://therning.org/magnus/archives/352#comment-125691</link>
		<dc:creator>Magnus</dc:creator>
		<pubDate>Fri, 06 Jun 2008 06:45:53 +0000</pubDate>
		<guid isPermaLink="false">http://therning.org/magnus/?p=352#comment-125691</guid>
		<description>&lt;p&gt;@Peter,&lt;/p&gt;

&lt;p&gt;Well, I had already done a bit of file-related stuff in Haskell (as you can see in other posts here) so I think being somewhat familiar with the relevant modules (mostly &lt;code&gt;System.IO.HVFS.Utils&lt;/code&gt;, &lt;code&gt;System.FilePath&lt;/code&gt; and &lt;code&gt;System.Directory&lt;/code&gt;) helped.  I also utilised &lt;code&gt;#haskell&lt;/code&gt; to find &lt;a href="http://hackage.haskell.org/cgi-bin/hackage-scripts/package/safe" rel="nofollow"&gt;safe&lt;/a&gt; which helped when dealing with missing lines in files.&lt;/p&gt;

&lt;p&gt;For the fourth problem I correctly guessed that finding primes would most easily be solved by using Google :-)  So I concentrated on how to do the sums (a combination of &lt;code&gt;take&lt;/code&gt; and &lt;code&gt;sum&lt;/code&gt;) and on finding the intersection of the infinate lists (exploiting the fact that the lists are sorted and that I only need to find the first item).&lt;/p&gt;

&lt;p&gt;As an aside I can tell that my colleague gave up on using generators for solving the problem in Python, instead he generated a list of all primes up till 10000000 in one go.  I guess he was helped by the fact that I had found my solution and that it was a much smaller number than we had guessed.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>@Peter,</p>
<p>Well, I had already done a bit of file-related stuff in Haskell (as you can see in other posts here) so I think being somewhat familiar with the relevant modules (mostly <code>System.IO.HVFS.Utils</code>, <code>System.FilePath</code> and <code>System.Directory</code>) helped.  I also utilised <code>#haskell</code> to find <a href="http://hackage.haskell.org/cgi-bin/hackage-scripts/package/safe" rel="nofollow">safe</a> which helped when dealing with missing lines in files.</p>
<p>For the fourth problem I correctly guessed that finding primes would most easily be solved by using Google <img src='http://therning.org/magnus/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />  So I concentrated on how to do the sums (a combination of <code>take</code> and <code>sum</code>) and on finding the intersection of the infinate lists (exploiting the fact that the lists are sorted and that I only need to find the first item).</p>
<p>As an aside I can tell that my colleague gave up on using generators for solving the problem in Python, instead he generated a list of all primes up till 10000000 in one go.  I guess he was helped by the fact that I had found my solution and that it was a much smaller number than we had guessed.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
