CSharpFeeds - All your C# feeds in one place.

Sunday, September 06, 2009

Use LINQ Aggregate to Multiply a Series of Digits

by ssmith via Blog on 9/6/2009 4:39:00 AM

The LINQ Aggregate() extension method uses a Func<int, int, int> to operate on items in a series.  If you want to use it, for example, to return the product of each value with its successor, you can do something like this: Func<int, int, int> producter = (one, two) => one * two; var result = subString.ToCharArray().ToDigits().Aggregate(producter); Of course, you don’t need the intermediate value.  You can simply use a lambda directly for the Aggregate ...

[ read more ]

Euler 7 Trivial with LINQ and Generators

by ssmith via Blog on 9/6/2009 3:53:00 AM

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 1000 ...

[ read more ]

Subscribe

New Feed

Product Spotlight

Recently Updated Sources

Legal Note

The content of the postings is owned by the respective author. CSharpFeeds is not responsible for the contents of the postings. This site is automatically generated and cannot be reviewed for abusive content. If you find abusive content on CSharpFeeds, please contact us. Designated trademarks and brands are the property of their respective owners. All rights reserved.

Advertise with us