<?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: Google Treasure Hunt</title>
	<atom:link href="http://knolleary.net/2008/05/19/google-treasure-hunt/feed/" rel="self" type="application/rss+xml" />
	<link>http://knolleary.net/2008/05/19/google-treasure-hunt/</link>
	<description>taking my thoughts for a walk</description>
	<pubDate>Tue, 06 Jan 2009 14:53:17 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.7</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Graham White: My Notes</title>
		<link>http://knolleary.net/2008/05/19/google-treasure-hunt/comment-page-1/#comment-10974</link>
		<dc:creator>Graham White: My Notes</dc:creator>
		<pubDate>Tue, 03 Jun 2008 08:54:24 +0000</pubDate>
		<guid isPermaLink="false">http://knolleary.net/?p=162#comment-10974</guid>
		<description>&lt;strong&gt;Google Treasure Hunt Question 3...&lt;/strong&gt;

I've been keeping up with the Google treasure hunt as a bit of fun rather than seriously going after any prizes.  At least one other guy at work has been joining me, Nick O'Leary has taken up the chal......</description>
		<content:encoded><![CDATA[<p><strong>Google Treasure Hunt Question 3&#8230;</strong></p>
<p>I&#8217;ve been keeping up with the Google treasure hunt as a bit of fun rather than seriously going after any prizes.  At least one other guy at work has been joining me, Nick O&#8217;Leary has taken up the chal&#8230;&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: kyb</title>
		<link>http://knolleary.net/2008/05/19/google-treasure-hunt/comment-page-1/#comment-10927</link>
		<dc:creator>kyb</dc:creator>
		<pubDate>Mon, 19 May 2008 21:54:31 +0000</pubDate>
		<guid isPermaLink="false">http://knolleary.net/?p=162#comment-10927</guid>
		<description>Garh! I forgot that the !! operator uses 0 indexing, so I've actually worked out the paths for 54x31 there, and 700x7001.

The line should of course have read
lpaths w h = (pathlist w) !! (h-1)

Giving the much more reasonable
12576607627510093891680 as the answer for 54x30.  Stupid functional languages make writing code terser, but they don't make you do unit tests.....</description>
		<content:encoded><![CDATA[<p>Garh! I forgot that the !! operator uses 0 indexing, so I&#8217;ve actually worked out the paths for 54&#215;31 there, and 700&#215;7001.</p>
<p>The line should of course have read<br />
lpaths w h = (pathlist w) !! (h-1)</p>
<p>Giving the much more reasonable<br />
12576607627510093891680 as the answer for 54&#215;30.  Stupid functional languages make writing code terser, but they don&#8217;t make you do unit tests&#8230;..</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: kyb</title>
		<link>http://knolleary.net/2008/05/19/google-treasure-hunt/comment-page-1/#comment-10926</link>
		<dc:creator>kyb</dc:creator>
		<pubDate>Mon, 19 May 2008 21:43:09 +0000</pubDate>
		<guid isPermaLink="false">http://knolleary.net/?p=162#comment-10926</guid>
		<description>When you can express it like that, a functional programming language is ideal for representing the problem.  In haskell, it's very similar to the maths you've written

paths :: Int -&#62; Int -&#62; Int
paths _ 1 = 1
paths 1 _ = 1
paths w h = (paths (w-1) h) + (paths w (h-1))

Sadly, this very simple clean result doesn't run particularly fast because of all the unnecessary recalculations.  It's fine for reasonable sized chess boards, but for 54x30, it just takes too long.

Fortunately, I can rewite it using infinite list data structures to do calculations for boards up to 700x700 pretty quickly.

pathlist 1 = 1 : (pathlist 1)
pathlist w = 1 : zipWith (+) (tail (pathlist (w-1))) (pathlist w)
lpaths w h = (pathlist w) !! h

&#62; lpaths 54 30
34795281102777926433648

&#62;lpaths 700 700
294959524837744306828252296100196431889118842418611448310042626887713844240301344669221418924201133834586362108669293514159261183838468398317529191441988702194010301504997962347728460441001014741345267577517951466709716033852841470615296707712692490701757399994671266386683080388904495703431988378768656808247129499221896960761043426375293304777943548918650717879698187751931573856298150842797277067333789380956594922720

The idea is that (pathlist w) is a function that returns an infinite list of all boards w x h, so the first number is w x 1, the second is the number of paths for w x 2 and so on.   The zipWith simply calculates the same way I was doing by hand - it's the number above plus the number to the left going on for ever.</description>
		<content:encoded><![CDATA[<p>When you can express it like that, a functional programming language is ideal for representing the problem.  In haskell, it&#8217;s very similar to the maths you&#8217;ve written</p>
<p>paths :: Int -&gt; Int -&gt; Int<br />
paths _ 1 = 1<br />
paths 1 _ = 1<br />
paths w h = (paths (w-1) h) + (paths w (h-1))</p>
<p>Sadly, this very simple clean result doesn&#8217;t run particularly fast because of all the unnecessary recalculations.  It&#8217;s fine for reasonable sized chess boards, but for 54&#215;30, it just takes too long.</p>
<p>Fortunately, I can rewite it using infinite list data structures to do calculations for boards up to 700&#215;700 pretty quickly.</p>
<p>pathlist 1 = 1 : (pathlist 1)<br />
pathlist w = 1 : zipWith (+) (tail (pathlist (w-1))) (pathlist w)<br />
lpaths w h = (pathlist w) !! h</p>
<p>&gt; lpaths 54 30<br />
34795281102777926433648</p>
<p>&gt;lpaths 700 700<br />
294959524837744306828252296100196431889118842418611448310042626887713844240301344669221418924201133834586362108669293514159261183838468398317529191441988702194010301504997962347728460441001014741345267577517951466709716033852841470615296707712692490701757399994671266386683080388904495703431988378768656808247129499221896960761043426375293304777943548918650717879698187751931573856298150842797277067333789380956594922720</p>
<p>The idea is that (pathlist w) is a function that returns an infinite list of all boards w x h, so the first number is w x 1, the second is the number of paths for w x 2 and so on.   The zipWith simply calculates the same way I was doing by hand - it&#8217;s the number above plus the number to the left going on for ever.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
