You can do something like this:
Func<int,int> Euler = total=> new List<int>() {3,5} .Select(m => ((int) (total-1) / m) * m * (((int) (total-1) / m) + 1) / 2) .Aggregate( (T, m) => T+=m);
You still have a double counter problem. I will think about it a little more.
Edit:
Here's a working (if a little inelegant) solution in LINQ:
var li = new List<int>() { 3, 5 }; Func<int, int, int> Summation = (total, m) => ((int) (total-1) / m) * m * (((int) (total-1) / m) + 1) / 2; Func<int,int> Euler = total=> li .Select(m => Summation(total, m)) .Aggregate((T, m) => T+=m) - Summation(total, li.Aggregate((T, m) => T*=m));
Can any of you improve this?
Explanation:
Remember that the summation formula for linear progression is n (n + 1) / 2. In the first case, when you have a multiple of 3.5 <10, you want Sum (3 + 6 + 9.5). Setting total = 10, you make a sequence of integers 1 .. (int) (total-1) / 3, and then sum the sequence and multiply by 3. You can easily see that we just set n = (int) (total- 1) / 3, then using the summation formula and multiplying by 3. A small algebra gives us a formula for the summation functor.
Jitters
source share