After reading through a few question on here I found out that asking questions about refining code golf code is not on topic. However in this case I'm not asking for the code to be golfed but re-ordered. I'll show the proposed question for clarity:
Code to print an alphabet triangle
The following code is an anonymous function that returns a string of an alphabet triangle. See the following code golf question for clarity.
My answer uses the following code:
Func<int, int, string[], string> f = (n, i, s) =>
{
s = new string[i = 51];
for (; --i > 24;)
{
for (n = 65; i + n < 116;)
s[i] += (char)n++;
for (n = 50 - i + 64; n > 64;)
s[i] += (char)n--;
s[50 - i] = s[i];
}
return string.Join("\n", s);
};
Console.WriteLine(f(0, 0, new string[0]));
I would like to reduce the two inner loops into oneloop but cannot see an easy way to do that. How can I do this?
(n,i,s)=>{s=new string[51];for(i=0;i<26;){for(n=65;n-65<i;)s[i]+=(char)n++;for(;n>64;)s[i]+=(char)n--;s[50-i]=s[i++];}return string.Join("\n",s);};
If you do Z in the second loop, you don't need to initialize. \$\endgroup\$