Euler 7 Trivial with LINQ and Generators

Date Published: 04 September 2009

Euler 7 Trivial with LINQ and Generators

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. Iā€™m really starting to dig using LINQ for this stuff.

Steve Smith

About Ardalis

Software Architect

Steve is an experienced software architect and trainer, focusing on code quality and Domain-Driven Design with .NET.