Skip to main content
Added ungolfed version
Source Link

As requested, the ungolfed version:

string ug(int n) { 

        // The sting we'll be returning
        string ret = ""; 

        // The width and height of the output
        int s = n * 2 + 1; 

        // for loop for width and height
        for (int height = 0; height < s; height++) 
        {
            for (int width = 0; width < s; width++) 
            {
                // Matches on top-left to bottom-right diagonal line
                if (height == width) 
                {
                    // If this is the center, write the 'sun'
                    if (width == n) 
                    {
                        ret += "O"; 
                    }
                    // If this is not the center, add the diagonal line character
                    else 
                    {
                        ret += "\\"; 
                    }
                }
                // Matches on top-right to bottom-left diagonal line
                else if (width == s - height - 1) 
                { 
                    ret += "/";
                }
                // Matches to add the center line
                else if (width == n) 
                { 
                    ret += "|";
                }
                // Matches to add the horizontal line
                else if (height == n) 
                { 
                    ret += "-";
                }
                // Matches all others
                else 
                { 
                    ret += " "; 
                } 
            } 
            // Add a newline to separate each line
            ret += "\n"; 
        } 
        return ret; 
    }

This is my first post so apologies if I've done something wrong. Any comments and corrections are very welcome.

This is my first post so apologies if I've done something wrong. Any comments and corrections are very welcome.

As requested, the ungolfed version:

string ug(int n) { 

        // The sting we'll be returning
        string ret = ""; 

        // The width and height of the output
        int s = n * 2 + 1; 

        // for loop for width and height
        for (int height = 0; height < s; height++) 
        {
            for (int width = 0; width < s; width++) 
            {
                // Matches on top-left to bottom-right diagonal line
                if (height == width) 
                {
                    // If this is the center, write the 'sun'
                    if (width == n) 
                    {
                        ret += "O"; 
                    }
                    // If this is not the center, add the diagonal line character
                    else 
                    {
                        ret += "\\"; 
                    }
                }
                // Matches on top-right to bottom-left diagonal line
                else if (width == s - height - 1) 
                { 
                    ret += "/";
                }
                // Matches to add the center line
                else if (width == n) 
                { 
                    ret += "|";
                }
                // Matches to add the horizontal line
                else if (height == n) 
                { 
                    ret += "-";
                }
                // Matches all others
                else 
                { 
                    ret += " "; 
                } 
            } 
            // Add a newline to separate each line
            ret += "\n"; 
        } 
        return ret; 
    }

This is my first post so apologies if I've done something wrong. Any comments and corrections are very welcome.

shortened slightly
Source Link

C#, 230230 226 bytes

string g(int n){string r="";int s=(n*2)+1;fors=n*2+1;for(int h=0;h<s;h++){for(int w=0;w<s;w++){if(h==w){if(w==n){r+="O";}else{r+="\\";}}else if(w==(sw==s-h)-1){r+="/";}else if(w==n){r+="|";}else if(h==n){r+="-";}else{r+=" ";}}r+="\n";}return r;}

This is my first post so apologies if I've done something wrong. Any comments and corrections are very welcome.

C#, 230 bytes

string g(int n){string r="";int s=(n*2)+1;for(int h=0;h<s;h++){for(int w=0;w<s;w++){if(h==w){if(w==n){r+="O";}else{r+="\\";}}else if(w==(s-h)-1){r+="/";}else if(w==n){r+="|";}else if(h==n){r+="-";}else{r+=" ";}}r+="\n";}return r;}

This is my first post so apologies if I've done something wrong. Any comments and corrections are very welcome.

C#, 230 226 bytes

string g(int n){string r="";int s=n*2+1;for(int h=0;h<s;h++){for(int w=0;w<s;w++){if(h==w){if(w==n){r+="O";}else{r+="\\";}}else if(w==s-h-1){r+="/";}else if(w==n){r+="|";}else if(h==n){r+="-";}else{r+=" ";}}r+="\n";}return r;}

This is my first post so apologies if I've done something wrong. Any comments and corrections are very welcome.

Improved formatting, unabbreviated uncommon abbreviation
Source Link
Alex A.
  • 24.7k
  • 5
  • 38
  • 119

C#, 230 bytes

string g(int n){string r="";int s=(n*2)+1;for(int h=0;h<s;h++){for(int w=0;w<s;w++){if(h==w){if(w==n){r+="O";}else{r+="\\";}}else if(w==(s-h)-1){r+="/";}else if(w==n){r+="|";}else if(h==n){r+="-";}else{r+=" ";}}r+="\n";}return r;}

C#, 230 bytes

string g(int n){string r="";int s=(n*2)+1;for(int h=0;h<s;h++){for(int w=0;w<s;w++){if(h==w){if(w==n){r+="O";}else{r+="\\";}}else if(w==(s-h)-1){r+="/";}else if(w==n){r+="|";}else if(h==n){r+="-";}else{r+=" ";}}r+="\n";}return r;}

This is my first post so apologies if I've done something wrong. Any C&Ccomments and corrections are very welcome.

C#, 230 bytes

string g(int n){string r="";int s=(n*2)+1;for(int h=0;h<s;h++){for(int w=0;w<s;w++){if(h==w){if(w==n){r+="O";}else{r+="\\";}}else if(w==(s-h)-1){r+="/";}else if(w==n){r+="|";}else if(h==n){r+="-";}else{r+=" ";}}r+="\n";}return r;}

This is my first post so apologies if I've done something wrong. Any C&C very welcome.

C#, 230 bytes

string g(int n){string r="";int s=(n*2)+1;for(int h=0;h<s;h++){for(int w=0;w<s;w++){if(h==w){if(w==n){r+="O";}else{r+="\\";}}else if(w==(s-h)-1){r+="/";}else if(w==n){r+="|";}else if(h==n){r+="-";}else{r+=" ";}}r+="\n";}return r;}

This is my first post so apologies if I've done something wrong. Any comments and corrections are very welcome.

Source Link
Loading