<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
		>
<channel>
	<title>Comments on: LINQ to prime numbers</title>
	<atom:link href="http://jacobcarpenter.wordpress.com/2008/03/26/linq-to-prime-numbers/feed/" rel="self" type="application/rss+xml" />
	<link>http://jacobcarpenter.wordpress.com/2008/03/26/linq-to-prime-numbers/</link>
	<description>Just another WordPress.com weblog</description>
	<lastBuildDate>Thu, 06 Aug 2009 13:21:45 +0000</lastBuildDate>
	<generator>http://wordpress.com/</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Jacob</title>
		<link>http://jacobcarpenter.wordpress.com/2008/03/26/linq-to-prime-numbers/#comment-114</link>
		<dc:creator>Jacob</dc:creator>
		<pubDate>Mon, 20 Oct 2008 15:33:58 +0000</pubDate>
		<guid isPermaLink="false">http://jacobcarpenter.wordpress.com/2008/03/26/linq-to-prime-numbers/#comment-114</guid>
		<description>Yeah; the prime generator in the post will calculate primes virutally infinitely. LINQPad only shows the first 1000 results in a sequence, when calling &lt;code&gt;.Dump()&lt;/code&gt;.

By calling &lt;code&gt;.Count()&lt;/code&gt;, you&#039;re trying to count the number of prime numbers the &quot;primes&quot; sequence contains.</description>
		<content:encoded><![CDATA[<p>Yeah; the prime generator in the post will calculate primes virutally infinitely. LINQPad only shows the first 1000 results in a sequence, when calling <code>.Dump()</code>.</p>
<p>By calling <code>.Count()</code>, you&#8217;re trying to count the number of prime numbers the &#8220;primes&#8221; sequence contains.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Fowl</title>
		<link>http://jacobcarpenter.wordpress.com/2008/03/26/linq-to-prime-numbers/#comment-113</link>
		<dc:creator>Fowl</dc:creator>
		<pubDate>Sun, 19 Oct 2008 11:22:52 +0000</pubDate>
		<guid isPermaLink="false">http://jacobcarpenter.wordpress.com/2008/03/26/linq-to-prime-numbers/#comment-113</guid>
		<description>I&#039;m not very adept at LINQ, but this had me puzzled.
var odds =
	from n in Enumerable.Range(0, int.MaxValue)
	select 3 + (long)n * 2;
var primes = (new[] { 2L }).Concat(
	from p in odds
	where ! odds.TakeWhile(odd =&gt; odd * odd  p % odd == 0)
	select p);
primes.Dump();
Runs in about 200ms for me, however when I change the last line to:
primes.Count().Dump();
It takes at least 5 minutes (that&#039;s when I gave up), at full CPU!</description>
		<content:encoded><![CDATA[<p>I&#8217;m not very adept at LINQ, but this had me puzzled.<br />
var odds =<br />
	from n in Enumerable.Range(0, int.MaxValue)<br />
	select 3 + (long)n * 2;<br />
var primes = (new[] { 2L }).Concat(<br />
	from p in odds<br />
	where ! odds.TakeWhile(odd =&gt; odd * odd  p % odd == 0)<br />
	select p);<br />
primes.Dump();<br />
Runs in about 200ms for me, however when I change the last line to:<br />
primes.Count().Dump();<br />
It takes at least 5 minutes (that&#8217;s when I gave up), at full CPU!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sam Jack</title>
		<link>http://jacobcarpenter.wordpress.com/2008/03/26/linq-to-prime-numbers/#comment-73</link>
		<dc:creator>Sam Jack</dc:creator>
		<pubDate>Mon, 21 Apr 2008 08:40:48 +0000</pubDate>
		<guid isPermaLink="false">http://jacobcarpenter.wordpress.com/2008/03/26/linq-to-prime-numbers/#comment-73</guid>
		<description>I&#039;ve written up a slightly more efficient prime generator that checks divisibility against previously generated primes rather than odd numbers: it uses a variant of the Unfold operation.
http://blog.functionalfun.net/2008/04/project-euler-problem-7-and-10.html</description>
		<content:encoded><![CDATA[<p>I&#8217;ve written up a slightly more efficient prime generator that checks divisibility against previously generated primes rather than odd numbers: it uses a variant of the Unfold operation.<br />
<a href="http://blog.functionalfun.net/2008/04/project-euler-problem-7-and-10.html" rel="nofollow">http://blog.functionalfun.net/2008/04/project-euler-problem-7-and-10.html</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Todd White</title>
		<link>http://jacobcarpenter.wordpress.com/2008/03/26/linq-to-prime-numbers/#comment-43</link>
		<dc:creator>Todd White</dc:creator>
		<pubDate>Fri, 28 Mar 2008 21:40:19 +0000</pubDate>
		<guid isPermaLink="false">http://jacobcarpenter.wordpress.com/2008/03/26/linq-to-prime-numbers/#comment-43</guid>
		<description>53 chars is my best so far.

new int[1000].Select((n,i)=&gt;i%3==0&#124;&#124;i%5==0?i:n).Sum()</description>
		<content:encoded><![CDATA[<p>53 chars is my best so far.</p>
<p>new int[1000].Select((n,i)=&gt;i%3==0||i%5==0?i:n).Sum()</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: jacobcarpenter</title>
		<link>http://jacobcarpenter.wordpress.com/2008/03/26/linq-to-prime-numbers/#comment-42</link>
		<dc:creator>jacobcarpenter</dc:creator>
		<pubDate>Thu, 27 Mar 2008 19:38:35 +0000</pubDate>
		<guid isPermaLink="false">http://jacobcarpenter.wordpress.com/2008/03/26/linq-to-prime-numbers/#comment-42</guid>
		<description>Oh; it also looks like your answer is off by 999 (which is divisible by 3).

The lame thing about Enumerable.Range is that the second argument is a sequence length (&quot;count&quot;), rather than an ending number. So your sequence starts at zero and contains 999 elements (ending at 998).

It sure seems like .Take() could have satisfied the need to limit a range to a specific length, but oh well.</description>
		<content:encoded><![CDATA[<p>Oh; it also looks like your answer is off by 999 (which is divisible by 3).</p>
<p>The lame thing about Enumerable.Range is that the second argument is a sequence length (&#8220;count&#8221;), rather than an ending number. So your sequence starts at zero and contains 999 elements (ending at 998).</p>
<p>It sure seems like .Take() could have satisfied the need to limit a range to a specific length, but oh well.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: jacobcarpenter</title>
		<link>http://jacobcarpenter.wordpress.com/2008/03/26/linq-to-prime-numbers/#comment-41</link>
		<dc:creator>jacobcarpenter</dc:creator>
		<pubDate>Thu, 27 Mar 2008 19:24:34 +0000</pubDate>
		<guid isPermaLink="false">http://jacobcarpenter.wordpress.com/2008/03/26/linq-to-prime-numbers/#comment-41</guid>
		<description>Well, for one, you&#039;ve got so much unnecessary whitespace. ;-)

Here&#039;s mine:

Enumerable.Range(1,999).Where(n=&gt;n%3==0&#124;&#124;n%5==0).Sum()</description>
		<content:encoded><![CDATA[<p>Well, for one, you&#8217;ve got so much unnecessary whitespace. <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<p>Here&#8217;s mine:</p>
<p>Enumerable.Range(1,999).Where(n=&gt;n%3==0||n%5==0).Sum()</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Judah</title>
		<link>http://jacobcarpenter.wordpress.com/2008/03/26/linq-to-prime-numbers/#comment-40</link>
		<dc:creator>Judah</dc:creator>
		<pubDate>Thu, 27 Mar 2008 19:03:04 +0000</pubDate>
		<guid isPermaLink="false">http://jacobcarpenter.wordpress.com/2008/03/26/linq-to-prime-numbers/#comment-40</guid>
		<description>54 characters? The best I can do is:

(from i in Enumerable.Range(0, 999)
where i % 3 == 0 &#124;&#124; i % 5 == 0
select i).Sum()

What do you ahve?</description>
		<content:encoded><![CDATA[<p>54 characters? The best I can do is:</p>
<p>(from i in Enumerable.Range(0, 999)<br />
where i % 3 == 0 || i % 5 == 0<br />
select i).Sum()</p>
<p>What do you ahve?</p>
]]></content:encoded>
	</item>
</channel>
</rss>
