<?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 (alternative solution)</title>
	<atom:link href="http://www.fsharp.it/2008/02/08/project-euler-in-f-problem-5-alternative-solution/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.fsharp.it/2008/02/08/project-euler-in-f-problem-5-alternative-solution/</link>
	<description>Functional programming on .Net</description>
	<lastBuildDate>Wed, 18 Aug 2010 12:04:06 +0200</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.5</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Joel</title>
		<link>http://www.fsharp.it/2008/02/08/project-euler-in-f-problem-5-alternative-solution/comment-page-1/#comment-9393</link>
		<dc:creator>Joel</dc:creator>
		<pubDate>Tue, 08 Dec 2009 09:51:45 +0000</pubDate>
		<guid isPermaLink="false">http://www.fsharp.it/2008/02/08/project-euler-in-f-problem-5-alternative-solution/#comment-9393</guid>
		<description>For what it&#039;s worth, this version returns the correct result in about 3.5 ms on my machine, compared to 28 ms for the code in your post. (According to System.Diagnostics.Stopwatch)

[fsharp]
let problem5 =
    // least common factor
    let rec lcf = function
        &#124; hd :: tl -&gt; hd :: lcf (List.map (fun x -&gt; if x % hd = 0 then x / hd else x) tl)
        &#124; [] -&gt; []
    [1..20] &#124;&gt; lcf &#124;&gt; List.fold (*) 1
[/fsharp]

I based the code on the algorithm described at the link below, but in F# I only needed 4 lines of code, vs 30+ lines of C#.

http://srtsolutions.com/blogs/billwagner/archive/2008/04/08/euler-problem-5.aspx</description>
		<content:encoded><![CDATA[<p>For what it&#8217;s worth, this version returns the correct result in about 3.5 ms on my machine, compared to 28 ms for the code in your post. (According to System.Diagnostics.Stopwatch)</p>
<pre class="brush: fsharp">
let problem5 =
    // least common factor
    let rec lcf = function
        | hd :: tl -&amp;gt; hd :: lcf (List.map (fun x -&amp;gt; if x % hd = 0 then x / hd else x) tl)
        | [] -&amp;gt; []
    [1..20] |&amp;gt; lcf |&amp;gt; List.fold (*) 1
</pre>
<p>I based the code on the algorithm described at the link below, but in F# I only needed 4 lines of code, vs 30+ lines of C#.</p>
<p><a href="http://srtsolutions.com/blogs/billwagner/archive/2008/04/08/euler-problem-5.aspx" rel="nofollow">http://srtsolutions.com/blogs/billwagner/archive/2008/04/08/euler-problem-5.aspx</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: claudio</title>
		<link>http://www.fsharp.it/2008/02/08/project-euler-in-f-problem-5-alternative-solution/comment-page-1/#comment-98</link>
		<dc:creator>claudio</dc:creator>
		<pubDate>Mon, 03 Mar 2008 18:21:08 +0000</pubDate>
		<guid isPermaLink="false">http://www.fsharp.it/2008/02/08/project-euler-in-f-problem-5-alternative-solution/#comment-98</guid>
		<description>To measure the execution time I store the value of DateTime.Now at the beginning and the end of the script and subtract them.

It is quite a &quot;naive&quot; solution but I simply wanted to get an idea of the execution time.</description>
		<content:encoded><![CDATA[<p>To measure the execution time I store the value of DateTime.Now at the beginning and the end of the script and subtract them.</p>
<p>It is quite a &#8220;naive&#8221; solution but I simply wanted to get an idea of the execution time.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Michiel Borkent</title>
		<link>http://www.fsharp.it/2008/02/08/project-euler-in-f-problem-5-alternative-solution/comment-page-1/#comment-97</link>
		<dc:creator>Michiel Borkent</dc:creator>
		<pubDate>Mon, 03 Mar 2008 17:47:39 +0000</pubDate>
		<guid isPermaLink="false">http://www.fsharp.it/2008/02/08/project-euler-in-f-problem-5-alternative-solution/#comment-97</guid>
		<description>Btw, how are you measuring the execution time? Using #time;;?</description>
		<content:encoded><![CDATA[<p>Btw, how are you measuring the execution time? Using #time;;?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Michiel Borkent</title>
		<link>http://www.fsharp.it/2008/02/08/project-euler-in-f-problem-5-alternative-solution/comment-page-1/#comment-96</link>
		<dc:creator>Michiel Borkent</dc:creator>
		<pubDate>Mon, 03 Mar 2008 17:37:39 +0000</pubDate>
		<guid isPermaLink="false">http://www.fsharp.it/2008/02/08/project-euler-in-f-problem-5-alternative-solution/#comment-96</guid>
		<description>... which can of course be written as [11I .. 20I] ;-)</description>
		<content:encoded><![CDATA[<p>&#8230; which can of course be written as [11I .. 20I] <img src='http://www.fsharp.it/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Michiel Borkent</title>
		<link>http://www.fsharp.it/2008/02/08/project-euler-in-f-problem-5-alternative-solution/comment-page-1/#comment-95</link>
		<dc:creator>Michiel Borkent</dc:creator>
		<pubDate>Mon, 03 Mar 2008 17:36:36 +0000</pubDate>
		<guid isPermaLink="false">http://www.fsharp.it/2008/02/08/project-euler-in-f-problem-5-alternative-solution/#comment-95</guid>
		<description>The list you feed to fold to generate the solution can be simplified itself, by observing that:

lcm(a,b) = b when b can be written   as a*n, with n being a natural number.

Examples: lcm(5,20) = 20, lcm(2,100) = 100 etc etc

So, instead of using the whole [1I .. 20I] use [11I; 12I; 13I; 14I; 15I; 16I; 17I; 18I; 19I; 20I]</description>
		<content:encoded><![CDATA[<p>The list you feed to fold to generate the solution can be simplified itself, by observing that:</p>
<p>lcm(a,b) = b when b can be written   as a*n, with n being a natural number.</p>
<p>Examples: lcm(5,20) = 20, lcm(2,100) = 100 etc etc</p>
<p>So, instead of using the whole [1I .. 20I] use [11I; 12I; 13I; 14I; 15I; 16I; 17I; 18I; 19I; 20I]</p>
]]></content:encoded>
	</item>
</channel>
</rss>
