static private string BuildLosange(int number)
StringBuilder builder = new StringBuilder(); int i = 2 * number - 1;
int numCol = (i / 2) + 1; int numLignes = (i / 2) + 1;
string[][] losange = new string[i][]; int start = number;
for (int j = 0; j < i; ++j) losange[j] = new string[i];
if (i == 1) losange[0][0] = "1"; else {
for (int y = 0; y < numLignes; ++y) { start = number; int numMinus = numLignes - y - 1; for (int x = 0; x < numMinus; ++x) losange[y][x] = "-"; for (int x = numMinus; x < numCol; ++x) losange[y][x] = (start--).ToString(); }
// Symétrie horizontale for (int y = 0; y < numLignes; ++y) { for (int x = numCol; x < i; ++x) { losange[y][x] = losange[y][i - 1 - x]; } }
// Symétrie verticale for (int y = numLignes; y < i; ++y) { for (int x = 0; x < i; ++x) { losange[y][x] = losange[i - 1 - y][x]; } } }
for (int y = 0; y < i; ++y) { for (int x = 0; x < i; ++x) { builder.Append(losange[y][x]); } builder.AppendLine(); } return builder.ToString(); } }
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre question