Reputation: 9194
I am trying to find the best way to handle the below:
I am really struggling with the most efficient way to perform this operation. I am really trying to cut down on the amount of times I have to loop over the data. Is there an obvious approach I am just glossing over?
Any suggestions on a possible path forward would be much appreciated.
new #1 = #1
new #2 = #2 * (1 - #1)
new #3 = #3 * (1 - #1) * (1 - #2)
new #4 = #4 * (1 - #1) * (1 - #2) * (1 - #3)
Upvotes: 0
Views: 54
Reputation: 100527
In-place replacement:
List<decimal> data =....
decimal multiplier = 1.0;
for (var i = 0; i < data.Count; i++)
{
var oldMultipleir = multiplier;
multiplier *= (1 - data[i]);
data[i] *= oldMultiplier;
}
Upvotes: 5