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:

1
2
3
4
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.

If you liked this post, consider subscribing to email updates about my new posts, or sharing it on Hacker News.

Keyboard shortcuts

?
Show this help
Esc
Close this help or an open menu
n
Next (newer) post: Use LINQ Aggregate to Multiply a Series of Digits
p
Previous (older) post: Windows Auto Sign On In Locked Mode
Tab
Move between links and buttons (Shift+Tab to go back)