1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
| class Program
{
private static readonly List<string> Lst_H = new List<string> { "H", "H", "H", "H", "H", "H", "H", "H", "H", "H" };
static void Main(string[] args)
{
Dictionary<int, List<string>> Dico = GetListF();
//*** Affiche les éléments de chaque liste :
foreach (var kvp in Dico)
{
Console.WriteLine($"{kvp.Key}: {string.Join(", ", kvp.Value)}");
}
}
private static Dictionary<int, List<string>> GetListF()
{
List<string> Lst_F = [];
Dictionary<int, List<string>> Dico = new Dictionary<int, List<string>>();
int nbrItemsInList = Lst_H.Count;
int rankInDico = 1;
for (int k = 0; k < nbrItemsInList; k++)
{
bool continueLoop = true;
for (int i = nbrItemsInList - 1; continueLoop && i > -1; i--)
{
Lst_F.Clear();
Lst_F.AddRange(Lst_H);
for (int j = 0; j <= k; j++)
{
if (i - j > -1)
{
Lst_F[i - j] = "F";
}
if (Lst_F[0] == "F")
{
continueLoop = false;
}
}
Dico[rankInDico] = new List<string>();
Dico[rankInDico].Add(string.Join(",", Lst_F));
rankInDico++;
}
}
return Dico;
}
} |
Partager