If you want to divide a vector X for Xn items, and store in a vector where t = Xn / l(t), assuming that l be the item count in t, and then you can go through them and modulating your index for each one:
int[] x = new int[] {1, 2, 3, 4, 5, 6, 7, 8}; // <~~~ var retorno = db.retornoDb.Tolist()
int[] t = new int[] {500, 501, 502, 503}; // <~~~ int[] IdTecnico
int xn = t.Length;
Dictionary<int, List<int>> tecnicosDivididos = new Dictionary<int, List<int>>();
// inicializa os itens no dicionario
foreach(int T in t) {
tecnicosDivididos.Add(T, new List<int>());
}
for(int i = 0; i < x.Length; i++) {
int I = i % xn;
int name = t[I];
(tecnicosDivididos[name] as List<int>).Add(x[i]);
}
foreach(KeyValuePair<int, List<int>> item in tecnicosDivididos) {
Console.WriteLine("{0} => {1}", item.Key, string.Join(", ", item.Value));
}
See working on .NET Fiddle.
In this way, Xn will always be the count of technicians present in t. The values are stored in a string, List<int>
, but in your case, you can pass to Tecnicos, List<retorno>
. You only need to inform a way to find the technicians by a key, either by name or by another single variable per item (in your case you use the ID, and implemented in the example the use of the ID).
You should probably change the type of x
because he is a int[]
and become a retorno[]
, but this is not necessary if you iterate the indexes of these returns. To generate this index vector, you could use the Enumerable.Range(0, retorno.Length)
, and then associate each index to each item in the retorno[]
.
I advise doing this and then pass the notation to Tecnicos
, thus, it will not break the algorithm. If you search for key by type Tecnicos
, the reference will make the key not exist, and soon will not have the expected result.
Note: the enumeration of returns by technician is not directly sequential, but modular. In fact, there will be no repeated items per technician, and the division will be equal if both are even. If the item count in X is odd, a technician will have an extra item. If the item count in T is odd, a technician will be missing an item.