Euler 7 Trivial with LINQ and Generators

Posted by: Steven Smith, on 06 Sep 2009 | View original | Bookmarked: 0 time(s)

Euler problem 7 requires returning the 10001st prime number.  It notes that the 6th prime number is 13 in the problem description.  Having already done some work with iterators and various number generators, including a Primes generator for previous Euler problems, the base case given in the problem can be reduced to this NUnit test:

public void SixthPrimeIs13()
{
    Assert.AreEqual(13, NumberGenerator.Primes().Take(6).Last());
}

Replacing the 6 with 10001 takes care of the rest.  Im really starting to dig using LINQ for this stuff.

Advertisement
Free Agile Project Management Tool from Telerik
TeamPulse Community Edition helps your team effectively capture requirements, manage project plans, assign and track work, and most importantly, be continually connected with each other.
Category: XLinq | Other Posts: View all posts by this blogger | Report as irrelevant | View bloggers stats | Views: 812 | Hits: 12

Similar Posts

  • LINQ in Action samples in LINQPad more
  • Creating LINQToTwitter library using LinqExtender more
  • Athena - A LINQ to flickr API (Release 1.4) more
  • Implementing SqlBulkCopy in Linq to Sql more
  • DevConnections Spring Slides and Demos more
  • Dynamic Queries and LINQ Expressions more
  • Is V1 of LINQ to SQL only suitable for RAD? more
  • Screencast: Enable Server Mode using LINQ (ASPxGridView & XtraGrid) more
  • Linq to SQL code posted in VB and C# more
  • Speed Development Time by 50% more

News Categories

.NET | Agile | Ajax | Architecture | ASP.NET | BizTalk | C# | Certification | Data | DataGrid | DataSet | Debugger | DotNetNuke | Events | GridView | IIS | Indigo | JavaScript | Mobile | Mono | Patterns and Practices | Performance | Podcast | Refactor | Regex | Security | Sharepoint | Silverlight | Smart Client Applications | Software | SQL | VB.NET | Visual Studio | W3 | WCF | WinFx | WPF | WSE | XAML | XLinq | XML | XSD