<?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: Project Euler in F# &#8211; Problem 5</title>
	<atom:link href="http://www.fsharp.it/2008/02/07/project-euler-in-f-problem-5/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.fsharp.it/2008/02/07/project-euler-in-f-problem-5/</link>
	<description>Functional programming on .Net</description>
	<lastBuildDate>Tue, 23 Feb 2010 22:18:36 +0100</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.5</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Project Euler in F# - Problem 5 (alternative solution) &#187; FSharp.it</title>
		<link>http://www.fsharp.it/2008/02/07/project-euler-in-f-problem-5/comment-page-1/#comment-41</link>
		<dc:creator>Project Euler in F# - Problem 5 (alternative solution) &#187; FSharp.it</dc:creator>
		<pubDate>Fri, 08 Feb 2008 14:57:01 +0000</pubDate>
		<guid isPermaLink="false">http://www.fsharp.it/2008/02/07/project-euler-in-f-problem-5/#comment-41</guid>
		<description>[...] was some buzz concerning my last post on Project Euler Problem 5, since the solution presented implemented a naive brute-force algorithm [...]</description>
		<content:encoded><![CDATA[<p>[...] was some buzz concerning my last post on Project Euler Problem 5, since the solution presented implemented a naive brute-force algorithm [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Paolo Bonzini</title>
		<link>http://www.fsharp.it/2008/02/07/project-euler-in-f-problem-5/comment-page-1/#comment-40</link>
		<dc:creator>Paolo Bonzini</dc:creator>
		<pubDate>Fri, 08 Feb 2008 09:54:23 +0000</pubDate>
		<guid isPermaLink="false">http://www.fsharp.it/2008/02/07/project-euler-in-f-problem-5/#comment-40</guid>
		<description>gcd(a,b)*lcm(a,b) = a*b holds always.  gcd(a,b,c)*lcm(a,b,c) = a*b*c does not hold, but you can exploit the associativity of lcm like this:

lcm(a,b,c)=lcm(lcm(a,b),c)

and then use the gcd(a,b)*lcm(a,b) = a*b identity to compute lcm.

in Smalltalk:

st&gt; Time millisecondsToRun: [ (2 to: 20) fold: [ :a :b &#124; a lcm: b ] ]
1
st&gt; Time millisecondsToRun: [ (2 to: 1000) fold: [ :a :b &#124; a lcm: b ] ]
14

and that&#039;s a 433-digit number...</description>
		<content:encoded><![CDATA[<p>gcd(a,b)*lcm(a,b) = a*b holds always.  gcd(a,b,c)*lcm(a,b,c) = a*b*c does not hold, but you can exploit the associativity of lcm like this:</p>
<p>lcm(a,b,c)=lcm(lcm(a,b),c)</p>
<p>and then use the gcd(a,b)*lcm(a,b) = a*b identity to compute lcm.</p>
<p>in Smalltalk:</p>
<p>st&gt; Time millisecondsToRun: [ (2 to: 20) fold: [ :a :b | a lcm: b ] ]<br />
1<br />
st&gt; Time millisecondsToRun: [ (2 to: 1000) fold: [ :a :b | a lcm: b ] ]<br />
14</p>
<p>and that&#8217;s a 433-digit number&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Michaelk</title>
		<link>http://www.fsharp.it/2008/02/07/project-euler-in-f-problem-5/comment-page-1/#comment-34</link>
		<dc:creator>Michaelk</dc:creator>
		<pubDate>Fri, 08 Feb 2008 01:16:02 +0000</pubDate>
		<guid isPermaLink="false">http://www.fsharp.it/2008/02/07/project-euler-in-f-problem-5/#comment-34</guid>
		<description>I noticed that the LCM of 1..18 was a factor of the LCM of 1..19, and the LCM of 1..19 was a factor of 1..20.

So, I just combined that with memoization, and got it working in Python (real 0m0.012s).</description>
		<content:encoded><![CDATA[<p>I noticed that the LCM of 1..18 was a factor of the LCM of 1..19, and the LCM of 1..19 was a factor of 1..20.</p>
<p>So, I just combined that with memoization, and got it working in Python (real 0m0.012s).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Michael</title>
		<link>http://www.fsharp.it/2008/02/07/project-euler-in-f-problem-5/comment-page-1/#comment-30</link>
		<dc:creator>Michael</dc:creator>
		<pubDate>Thu, 07 Feb 2008 17:01:23 +0000</pubDate>
		<guid isPermaLink="false">http://www.fsharp.it/2008/02/07/project-euler-in-f-problem-5/#comment-30</guid>
		<description>claudio 
if you think about it the binary gcd(a,b)*lm(a,b) = a*b doesn&#039;t hold in the general case. gcd(1,..,20) should obviously be 1 and lcm(1,..,20) is obviously not 1*2*...*20 which means lcm(1,..,20) \not= 1*...*20/gcd(1,..,20)

But lcm is still easy it&#039;s just the max of each exponent of the unique factorization of each of the number you take lcm over.</description>
		<content:encoded><![CDATA[<p>claudio<br />
if you think about it the binary gcd(a,b)*lm(a,b) = a*b doesn&#8217;t hold in the general case. gcd(1,..,20) should obviously be 1 and lcm(1,..,20) is obviously not 1*2*&#8230;*20 which means lcm(1,..,20) \not= 1*&#8230;*20/gcd(1,..,20)</p>
<p>But lcm is still easy it&#8217;s just the max of each exponent of the unique factorization of each of the number you take lcm over.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Matt</title>
		<link>http://www.fsharp.it/2008/02/07/project-euler-in-f-problem-5/comment-page-1/#comment-29</link>
		<dc:creator>Matt</dc:creator>
		<pubDate>Thu, 07 Feb 2008 17:00:43 +0000</pubDate>
		<guid isPermaLink="false">http://www.fsharp.it/2008/02/07/project-euler-in-f-problem-5/#comment-29</guid>
		<description>Here&#039;s my solution with no programming required
http://methodoverload.blogspot.com/2008/02/project-euler-5-and-number-theory.html</description>
		<content:encoded><![CDATA[<p>Here&#8217;s my solution with no programming required<br />
<a href="http://methodoverload.blogspot.com/2008/02/project-euler-5-and-number-theory.html" rel="nofollow">http://methodoverload.blogspot.com/2008/02/project-euler-5-and-number-theory.html</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: claudio</title>
		<link>http://www.fsharp.it/2008/02/07/project-euler-in-f-problem-5/comment-page-1/#comment-28</link>
		<dc:creator>claudio</dc:creator>
		<pubDate>Thu, 07 Feb 2008 16:53:44 +0000</pubDate>
		<guid isPermaLink="false">http://www.fsharp.it/2008/02/07/project-euler-in-f-problem-5/#comment-28</guid>
		<description>Hi, thanks for the suggestion.

I plan to write a new post soon presenting your solution and showing the huge difference between a brute-force approach and a &quot;smart&quot; one.

The goal of this series of articles is to introduce people to  functional programming, trying to translate the basic algorithms that come to mind into F# code, and hoping that the readers will try to find their own solution before I show mine.


BTW, I also added the comment subscription plugin that you suggested, thanks!</description>
		<content:encoded><![CDATA[<p>Hi, thanks for the suggestion.</p>
<p>I plan to write a new post soon presenting your solution and showing the huge difference between a brute-force approach and a &#8220;smart&#8221; one.</p>
<p>The goal of this series of articles is to introduce people to  functional programming, trying to translate the basic algorithms that come to mind into F# code, and hoping that the readers will try to find their own solution before I show mine.</p>
<p>BTW, I also added the comment subscription plugin that you suggested, thanks!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Beetle B.</title>
		<link>http://www.fsharp.it/2008/02/07/project-euler-in-f-problem-5/comment-page-1/#comment-27</link>
		<dc:creator>Beetle B.</dc:creator>
		<pubDate>Thu, 07 Feb 2008 16:35:22 +0000</pubDate>
		<guid isPermaLink="false">http://www.fsharp.it/2008/02/07/project-euler-in-f-problem-5/#comment-27</guid>
		<description>If you know a bit more math, this is even easier:

lcm(a1, a2, ...) = (a1*a2*a3*...)/gcd(a1,a2,...)

where gcd is the greatest common divisor and can be calculated using Euclid&#039;s algorithm. 

Basically, I calculated the lcm of 2 and 3, and then the lcm of the result and 4, the lcm of the result and 5, etc.

0.1 ms in Python (interpreted!) on a P4 2.53 GHz machine. 

Oh, and BTW, since you&#039;re using Wordpress, you may want to get the plugin that allows people who post comments to subscribe to the comments via email (yes, I know you have an RSS, but I don&#039;t want to crowd my RSS aggregator for simple things like these). Otherwise, it&#039;ll be hard for commenters to maintain a conversation with you.</description>
		<content:encoded><![CDATA[<p>If you know a bit more math, this is even easier:</p>
<p>lcm(a1, a2, &#8230;) = (a1*a2*a3*&#8230;)/gcd(a1,a2,&#8230;)</p>
<p>where gcd is the greatest common divisor and can be calculated using Euclid&#8217;s algorithm. </p>
<p>Basically, I calculated the lcm of 2 and 3, and then the lcm of the result and 4, the lcm of the result and 5, etc.</p>
<p>0.1 ms in Python (interpreted!) on a P4 2.53 GHz machine. </p>
<p>Oh, and BTW, since you&#8217;re using Wordpress, you may want to get the plugin that allows people who post comments to subscribe to the comments via email (yes, I know you have an RSS, but I don&#8217;t want to crowd my RSS aggregator for simple things like these). Otherwise, it&#8217;ll be hard for commenters to maintain a conversation with you.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
