Click here to Skip to main content
15,889,281 members
Home / Discussions / C#
   

C#

 
AnswerRe: Coding Challenge Pin
Peter_in_278027-Aug-17 1:41
professionalPeter_in_278027-Aug-17 1:41 
AnswerRe: Coding Challenge Pin
Richard Deeming29-Aug-17 2:28
mveRichard Deeming29-Aug-17 2:28 
GeneralRe: Coding Challenge Pin
Mycroft Holmes4-Sep-17 21:06
professionalMycroft Holmes4-Sep-17 21:06 
SuggestionRe: Coding Challenge Pin
Richard Deeming5-Sep-17 1:55
mveRichard Deeming5-Sep-17 1:55 
GeneralRe: Coding Challenge Pin
Mycroft Holmes4-Sep-17 22:24
professionalMycroft Holmes4-Sep-17 22:24 
GeneralRe: Coding Challenge Pin
Pete O'Hanlon4-Sep-17 23:24
mvePete O'Hanlon4-Sep-17 23:24 
GeneralRe: Coding Challenge Pin
Richard Deeming5-Sep-17 2:04
mveRichard Deeming5-Sep-17 2:04 
AnswerRe: Coding Challenge Pin
Pete O'Hanlon29-Aug-17 3:53
mvePete O'Hanlon29-Aug-17 3:53 
The evil side in me likes a challenge. I had a little bit of a play around and came up with this (where we assume that Values is your list of double value inputs; this copes with arbitrary lengths of Values as long as it's greater than 2):
C#
Values.Select(
  p =>
    new {avg = Values.Skip(1).Where(x => index < Values.Count).Select(x => (x - Values[index++])/x).Average()})
  .Select(x => new {x, last = Values.Last()})
  .Select(@t => new {@t, aver = @t.last + (@t.last*@t.x.avg)})
  .Select(@t => new {value1 = @t.aver, value2 = @t.aver + (@t.aver*@t.@t.x.avg)}).First();
Taking inspiration from Richard's excellent answer, this can be further simplified into:
C#
Values.Select(
  p =>
    new
    {
      avg = Values.Skip(1).Take(Values.Count - 1)
        .Zip(Values, (second, first) => (second - first)/second)
        .Average()
    })
  .Select(x => new {x, last = Values.Last()})
  .Select(@t => new {@t, aver = @t.last + (@t.last*@t.x.avg)})
  .Select(@t => new {value1 = @t.aver, value2 = @t.aver + (@t.aver*@t.@t.x.avg)}).First();

This space for rent


modified 29-Aug-17 10:25am.

Questionc++ const in c# (I assume, once again) Pin
User 1106097925-Aug-17 8:04
User 1106097925-Aug-17 8:04 
AnswerRe: c++ const in c# (I assume, once again) Pin
OriginalGriff25-Aug-17 8:37
mveOriginalGriff25-Aug-17 8:37 
GeneralRe: c++ const in c# (I assume, once again) Pin
User 1106097925-Aug-17 8:43
User 1106097925-Aug-17 8:43 
GeneralRe: c++ const in c# (I assume, once again) Pin
User 1106097925-Aug-17 9:01
User 1106097925-Aug-17 9:01 
GeneralRe: c++ const in c# (I assume, once again) Pin
harold aptroot25-Aug-17 8:41
harold aptroot25-Aug-17 8:41 
GeneralRe: c++ const in c# (I assume, once again) Pin
User 1106097925-Aug-17 8:47
User 1106097925-Aug-17 8:47 
AnswerRe: c++ const in c# (I assume, once again) Pin
jschell25-Aug-17 9:40
jschell25-Aug-17 9:40 
GeneralRe: c++ const in c# (I assume, once again) Pin
User 1106097925-Aug-17 9:50
User 1106097925-Aug-17 9:50 
AnswerRe: c++ const in c# (I assume, once again) Pin
Pete O'Hanlon25-Aug-17 12:19
mvePete O'Hanlon25-Aug-17 12:19 
GeneralRe: c++ const in c# (I assume, once again) Pin
User 1106097925-Aug-17 12:47
User 1106097925-Aug-17 12:47 
AnswerRe: c++ const in c# (I assume, once again) Pin
Gerry Schmitz26-Aug-17 8:54
mveGerry Schmitz26-Aug-17 8:54 
AnswerRe: c++ const in c# (I assume, once again) Pin
Bernhard Hiller28-Aug-17 3:39
Bernhard Hiller28-Aug-17 3:39 
GeneralRe: c++ const in c# (I assume, once again) Pin
User 1106097928-Aug-17 3:54
User 1106097928-Aug-17 3:54 
QuestionCreate .NET COM dll as existing C++ COM Pin
MrKBA24-Aug-17 22:38
MrKBA24-Aug-17 22:38 
AnswerRe: Create .NET COM dll as existing C++ COM Pin
Pete O'Hanlon24-Aug-17 22:44
mvePete O'Hanlon24-Aug-17 22:44 
GeneralRe: Create .NET COM dll as existing C++ COM Pin
MrKBA25-Aug-17 0:41
MrKBA25-Aug-17 0:41 
GeneralRe: Create .NET COM dll as existing C++ COM Pin
Pete O'Hanlon25-Aug-17 0:57
mvePete O'Hanlon25-Aug-17 0:57 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.