Hi,
I’m struggling to get my program to pass the tests but I can’t reproduce the failures exercism is flagging in my own IDE.
I’ve passed it into chatGPT put it only suggests style changes, can anybody give any insights?
Thanks in advance.
using System;
using System.Text;
public static class Diamond
{
public static string Make(char target)
{
if (target < 'A' || target > 'Z')
throw new ArgumentOutOfRangeException(nameof(target), "Target must be between 'A' and 'Z'.");
var sb = new StringBuilder();
int size = target - 'A';
for (int i = 0; i <= size; i++)
{
sb.AppendLine(DrawLine(size - i, (char)('A' + i), i));
}
for (int i = size - 1; i >= 0; i--)
{
sb.AppendLine(DrawLine(size - i, (char)('A' + i), i));
}
return sb.ToString();
}
private static string DrawLine(int padding, char letter, int innerSpace)
{
var sb = new StringBuilder();
sb.Append(new string('·', padding));
sb.Append(letter);
if (innerSpace > 0)
{
sb.Append(new string('·', innerSpace * 2 - 1));
sb.Append(letter);
}
sb.Append(new string('·', padding));
return sb.ToString();
}
}