0
\$\begingroup\$

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?

\$\endgroup\$
  • 1
    \$\begingroup\$ I don't want to join CodeGolf to comment there. Try (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\$ – mdfst13 Aug 5 '16 at 15:52
  • \$\begingroup\$ @mdfst13 Oh thanks! \$\endgroup\$ – TheLethalCoder Aug 5 '16 at 16:03
  • \$\begingroup\$ I would think any golfed code would be too terribly formatted for good review. If it's non-golfed (like above) then I don't see why not. \$\endgroup\$ – Raystafarian Sep 1 '16 at 20:08
8
\$\begingroup\$

No.

Your question isn't asking to improve code quality. Instead it's asking how to golf, 'semi'-golfed code.

Lets say you post your question, you get the answer 'don't use an anonymous function'. This is almost definitely useless to you, as you do not want good code. Instead you're just asking for a different way to golf your code. And we do not do that.

If however you do want to have answers such as 'don't use an anonymous function', and they will genuinely help you, then it may be ok to post your code, but try your best to not make it golfed. Proper functions rather than anon functions, more descriptive variables not one letters, etc.

\$\endgroup\$
  • \$\begingroup\$ I can certainly update the code so that it doesn't look like golfed code but the main reason asking is to try and combine the loops, is that on topic? \$\endgroup\$ – TheLethalCoder Aug 5 '16 at 11:47
  • \$\begingroup\$ @TheLethalCoder As far as I know that has no binding on being on/off-topic. But the question may be completely ignored. \$\endgroup\$ – Peilonrayz Aug 5 '16 at 11:59
  • \$\begingroup\$ Okay thanks, I'll avoid asking it \$\endgroup\$ – TheLethalCoder Aug 5 '16 at 11:59

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .