C# Tupel group limitation
Posted
by
user609511
on Stack Overflow
See other posts from Stack Overflow
or by user609511
Published on 2011-11-24T09:41:10Z
Indexed on
2011/11/24
9:52 UTC
Read the original article
Hit count: 287
How can i controll the loop of Tupel Repeatation ?
Someone has give me a hint about my algorithm. I modified a little bit his algorithm.
int LimCol = Convert.ToInt32(LimitColis);
result = oListTUP
.GroupBy(x => x.Item1)
.Select(g => new
{
Key = g.Key,
Sum = g.Sum(x => x.Item2),
Poids = g.Sum(x => x.Item3),
})
.Select(p => new
{
Key = p.Key,
Items = Enumerable.Repeat(LimCol , p.Sum / LimCol).Concat(Enumerable.Repeat(p.Sum % LimCol, 1)),
CalculPoids = p.Poids / (Enumerable.Repeat(LimCol, p.Sum / LimCol).Concat(Enumerable.Repeat(p.Sum % LimCol, 1))).Count()
})
.SelectMany(p => p.Items.Select(i => Tuple.Create(p.Key, i, p.CalculPoids)))
.ToList();
foreach (var oItem in result)
{
Label1.Text += oItem.Item1 + "--" + oItem.Item2 + "--" + oItem.Item3 + "<br>";
}
the result with LimCol = 3
as you can see i colored with red is the problem. i expected:
0452632--3--3,75
0452632--3--3,75
0452632--3--3,75
0452632--3--3,75
essai 49--3--79,00
essai 49--2--79,00
Thanks you in advance
© Stack Overflow or respective owner