21
\$\begingroup\$

Problem

Inspired by a previous challenge doing something similar

Given positive integer input n output a shape that follows this pattern:

input n=1:

* *
 *
* *

input n=2:

**  **
 ****
  **
 ****
**  **

input n=3:

***   ***
 *** ***
  *****
   ***
  *****
 *** ***
***   ***

and so on...

It has these properties:

n*2+1 lines tall

the "arms" are n wide except when they merge

the center line is n wide

if n is even the lines above and below the center are n*2 wide

if n is odd the lines above and below the center are n*2-1 wide

Rules

  • Trailing newlines accepted
  • Standard loopholes apply
  • Shortest bytes win
  • Output may be print out or a string or array of strings

Edits

  • n=0 doesn't need to be handled
  • Trailing spaces allowed
\$\endgroup\$
4
  • 2
    \$\begingroup\$ Is it okay if the output has 1 instead of * and 0 instead of space? \$\endgroup\$ Jun 13, 2017 at 13:59
  • \$\begingroup\$ Can our patterns be 0-indexed? \$\endgroup\$
    – Leaky Nun
    Jun 13, 2017 at 14:02
  • \$\begingroup\$ @JungHwanMin I will allow it but then you aren't allowed to win, might be swayed if you are most upvoted. \$\endgroup\$
    – LiefdeWen
    Jun 13, 2017 at 14:05
  • \$\begingroup\$ @LeakyNun 0 Indexed is fine \$\endgroup\$
    – LiefdeWen
    Jun 13, 2017 at 14:05

20 Answers 20

14
\$\begingroup\$

MATL, 16 bytes

EQXyG:Y+tP+g42*c

Try it online!

Explanation

Consider input 2 as an example. Stack contents are shown with more recent ones below.

EQ    % Implicitly input n. Push 2*n+1
      %   STACK: 5
Xy    % Identity matrix of that size
      %   STACK: [1 0 0 0 0;
                  0 1 0 0 0;
                  0 0 1 0 0;
                  0 0 0 1 0;
                  0 0 0 0 1]
G:    % Push [1 2 ... n]
      %   STACK: [1 0 0 0 0;
                  0 1 0 0 0;
                  0 0 1 0 0;
                  0 0 0 1 0;
                  0 0 0 0 1],
                 [1 2]
Y+    % 2D convolution, extending size
      %   STACK: [1 2 0 0 0 0;
                  0 1 2 0 0 0;
                  0 0 1 2 0 0;
                  0 0 0 1 2 0;
                  0 0 0 0 1 2]
tP+   % Duplicate, flip vertically, add
      %   STACK: [1 2 0 0 2 1;
                  0 1 2 1 2 0;
                  0 0 1 4 0 0;
                  0 1 2 1 2 0;
                  1 2 0 0 1 2]
g     % Convert to logical
      %   STACK: [1 1 0 0 1 1;
                  0 1 1 1 1 0;
                  0 0 1 1 0 0;
                  0 1 1 1 1 0;
                  1 1 0 0 1 1]
42*   % Multiply by 42.
      %   STACK: [42 42  0  0 42 42;
                   0 42 42 42 42  0;
                   0  0 42 42  0  0;
                   0 42 42 42 42  0;
                  42 42  0  0 42 42]
c     % Convert to char. Char 42 is '*'. Char 0 is displayed as space
      %   STACK: ['**  **';
                  ' **** ';
                  '  **  ';
                  ' **** ';
                  '**  **']
\$\endgroup\$
5
  • \$\begingroup\$ You're faster than me... \$\endgroup\$
    – Leaky Nun
    Jun 13, 2017 at 14:00
  • \$\begingroup\$ @LeakyNun Very rarely :-) \$\endgroup\$
    – Luis Mendo
    Jun 13, 2017 at 14:01
  • \$\begingroup\$ I wish Jelly had 2D convolution... I had to append 0 in each row and then apply vectorized sum... \$\endgroup\$
    – Leaky Nun
    Jun 13, 2017 at 14:13
  • 1
    \$\begingroup\$ @LeakyNun You know what they say about convolution... \$\endgroup\$
    – Luis Mendo
    Jun 13, 2017 at 14:15
  • 1
    \$\begingroup\$ @LuisMendo In my heart you are the winner for using convolution, brings back such nice memories. \$\endgroup\$
    – LiefdeWen
    Jun 15, 2017 at 6:23
10
\$\begingroup\$

Charcoal, 13 12 bytes

Thanks to @ErikTheOutgolfer for a byte

FN«PX⁺*×*Iθ→

Try it online!

This is my first ever Charcoal answer, and I'm pretty sure it's not golfed as well as it could be, but I figured I'd start somewhere.

 FN«            # For input() (i in range(0,input()))
     P           # Print
       X          # In an 'X' shape
        ⁺*×*Iθ   # '*'+'*'*int(first_input)
               →  # Move the cursor right one
\$\endgroup\$
6
  • \$\begingroup\$ You can use for -1. \$\endgroup\$ Jun 13, 2017 at 16:47
  • \$\begingroup\$ @EriktheOutgolfer I knew there had to be a way to do that! Thank you! \$\endgroup\$
    – nmjcman101
    Jun 13, 2017 at 16:49
  • \$\begingroup\$ And yes it actually seems as golfed as it can be. \$\endgroup\$ Jun 13, 2017 at 16:56
  • \$\begingroup\$ @EriktheOutgolfer It wasn't before you came along anyway :) \$\endgroup\$
    – nmjcman101
    Jun 13, 2017 at 17:00
  • 1
    \$\begingroup\$ @thomasrutter Charcoal has it's own custom code-page with 256 bytes, where each of those characters is 1 byte. So it's not encoded in ASCII, where some of these characters would indeed be multiple bytes. nmjcman101 +1 btw. Was trying my first Charcoal answer as well yesterday, but it didn't really worked out in the few minutes I had before going home from work. So you've beat me to it. I did learn some things from your answer, so thanks for that. \$\endgroup\$ Jun 14, 2017 at 6:39
9
\$\begingroup\$

Jelly, 15 bytes

Ḥ‘Ḷ⁶ẋ;€”*ẋ$»Ṛ$Y

Try it online!

\$\endgroup\$
5
  • \$\begingroup\$ Very nice. 8 bytes short of me. \$\endgroup\$
    – Leaky Nun
    Jun 13, 2017 at 14:41
  • \$\begingroup\$ @LeakyNun The straightforward approach helps quite a bit. \$\endgroup\$ Jun 13, 2017 at 14:42
  • \$\begingroup\$ A very nice approach \$\endgroup\$ Jun 13, 2017 at 14:45
  • \$\begingroup\$ @JonathanAllan Yeah, especially tfw you learn » vectorizes... \$\endgroup\$ Jun 13, 2017 at 14:46
  • 1
    \$\begingroup\$ I really like your username! But I wish you used "vi" or "vim" instead, so you could choose "Erik the vi King" ... (Monty Python fan here ...) \$\endgroup\$ Jun 14, 2017 at 14:38
4
\$\begingroup\$

05AB1E, 18 bytes

Å4bS{I·ƒDÂ~„ *èJ,À

Try it online!

Explanation

Example for n=2

Å4                   # push a list of 4s with length as the input
                     # STACK: [4,4]
  b                  # convert each to binary
                     # STACK: [100, 100]
   S{                # split into digit list and sort
                     # STACK: [0, 0, 0, 0, 1, 1]
     I·ƒ             # input*2+1 times do
        D            # duplicate top of stack
                     # 1st iteration: [0, 0, 0, 0, 1, 1], [0, 0, 0, 0, 1, 1]
                     # 2nd iteration: [0, 0, 0, 1, 1, 0], [0, 0, 0, 1, 1, 0]
                     # 3rd iteration: [0, 0, 1, 1, 0, 0], [0, 0, 1, 1, 0, 0]
         Â~          # or each item in the duplicate with its reverse
                     # 1st iteration: [0, 0, 0, 0, 1, 1], [1, 1, 0, 0, 1, 1]
                     # 2nd iteration: [0, 0, 0, 1, 1, 0], [0, 1, 1, 1, 1, 0]
                     # 3rd iteration: [0, 0, 1, 1, 0, 0], [0, 0, 1, 1, 0, 0]
           „ *èJ     # use the resulting binary list to index into the string " *"
                     # 1st iteration: [0, 0, 0, 0, 1, 1], "**  **"
                     # 2nd iteration: [0, 0, 0, 1, 1, 0], " **** "
                     # 3rd iteration: [0, 0, 1, 1, 0, 0], "  **  "
                ,    # print
                 À   # rotate list left
\$\endgroup\$
4
\$\begingroup\$

V, 18 17 bytes

Saved a byte thanks to @DJMcMayhem's input trick.

Àé*ÄJÀälÀñ2ÙÀl2x>

Try it online!

Explanation

Àé*ÄJÀäl

This inserts [n]*'*'+[n]*' '+[n]*'*'

        Àñ        ' [arg] times
          2Ù      ' Duplicate the current line down twice
            Àl    ' Move right [arg] times
              2x  ' Delete two characters
                > ' Indent this line one space

Each iteration of the loop the buffer goes from

|**   ***

To

***   ***
 |** ***
***   ***

Where | is the cursor with a * under it

\$\endgroup\$
2
  • \$\begingroup\$ Wow. You waaay outgolfed me. Good job! A few tips: You could do Àé*ÄJÀäl instead of Àá*Àá Àá*, and you can do <M-c>, i.e. ã (mnemonic: center) to move to the middle of the line, which is a byte shorter than Àl. Try it online! \$\endgroup\$
    – DJMcMayhem
    Jun 13, 2017 at 15:44
  • \$\begingroup\$ @DJMcMayhem I'm trying to talk to you in a bunch of different places. I'm going to steal the first suggestion I think, but the <M-c> breaks for higher numbers \$\endgroup\$
    – nmjcman101
    Jun 13, 2017 at 15:45
3
\$\begingroup\$

V, 23 bytes

Àé*ÄJÀälÀñÙãlxx>ñyHæGVp

Try it online!

Hexdump:

00000000: c0e9 2ac4 4ac0 e46c c0f1 d9e3 6c78 783e  ..*.J..l....lxx>
00000010: f179 48e6 4756 70                        .yH.GVp

For whatever reason, this challenge is significantly harder in V than the last one. Since our general approach of n times, grow an 'x' won't work here, we'll instead construct the top of the X, copy it and flip it, then attaching the two parts together.

Explanation:

Àé*ÄJÀäl                " Insert ('*' * n) + (' ' * n) + ('*' * n) 
                        " The obvious way would be 'Àé*ÀÁ ÀÁ*', but this 
                        " non-obvious way saves us a byte
        Àñ      ñ       " 'n' times:
          Ù             "   Duplicate this line (below us)
           ãl           "   Move to the center of this line
             xx         "   Delete two characters
               >        "   And indent this line with one space.

Doing the indent at the end of the loop, allows us to take advantage of implicit endings. This also conveniently creates n+1 lines, which is exactly the top half of the 'X'. Let's say the input was 4. Then at this point, the buffer looks like this:

****    ****
 ****  ****
  ********
   ******
    ****

And we're on the last line. So then we:

                yH      " Copy the whole buffer and move to the first line
                  æG    " Reverse every line
                    Vp  " And paste what we just copied *over* the current
                        " line, deleting it in the process
\$\endgroup\$
2
  • \$\begingroup\$ I did the ãxx thing at first too, but I think it breaks for e.g. n = 8? \$\endgroup\$
    – nmjcman101
    Jun 13, 2017 at 15:44
  • \$\begingroup\$ @nmjcman101 Ah, you're right. It's fine if you do ãl, or if you indent before centering though, but that doesn't actually save any bytes. I don't understand why it works for smaller numbers though. \$\endgroup\$
    – DJMcMayhem
    Jun 13, 2017 at 15:47
3
\$\begingroup\$

C#, 139 130 115 bytes

-1 byte by creating a string and calling WriteLine, thus saving the check for the new line.
-6 bytes thanks to Kevin and his master golfing techniques!
-2 bytes by replacing n*3-n with n*2.
-15 bytes after Kevin kindly pointed me in the right direction: I can just return the string instead of printing it, thus saving the call to System.Console.WriteLine(). And some other tips also...

n=>{var s="";for(int i,j=0;j<=n*2;j++,s+='\n')for(i=0;i<n*3;)s+=i>=j&i<j+n|i<=n*3-j-1&i++>=n*2-j?'*':' ';return s;}

Try it online!

Ungolfed:

class Program
{
    static void Main(string[] args)
    {
        System.Func<int, string> g = n =>
        {
            var s = "";
            for (int i, j = 0; j <= n*2; j++, s += '\n')
                for (i = 0; i < n*3;)
                    s += i >= j & i < j+n | i <= n*3-j-1 & i++ >= n*2-j ? '*' : ' ';
            return s;
        };

        System.Console.Write(f(1));
        System.Console.Write(f(2));
        System.Console.Write(f(3));
        System.Console.Write(f(5));
        System.Console.Write(f(8));

        System.Console.ReadKey();
    }
}

It just iterates along the rows and columns of the space needed to print the big X and prints either a '*' or a ' ' depending on the condition.

\$\endgroup\$
8
  • 1
    \$\begingroup\$ +1! Some small things to golf. All the && can be & and || can be | in this case. for(int j=0; can be for(int j=0,i; and then you can remove the int in front of the i in the inner loop. Also, after the first change of & and |, you can also remove the i++ inside the for-loop, and change i==n*3-1?... to i++==n*3-1?.... \$\endgroup\$ Jun 14, 2017 at 6:58
  • \$\begingroup\$ @KevinCruijssen thank you very much! I changed the inner loop and now I create a string so I can call WriteLine, saved just 1 byte. So now I'm not sure what to do with your last advice. \$\endgroup\$
    – Charlie
    Jun 14, 2017 at 7:12
  • 1
    \$\begingroup\$ Btw, why the System.Console.WriteLine? Returning the string: n=>{string s="";for(int i,j=0;j<n*2+1;j++,s+="\n")for(i=0;i<n*3;)s+=i>=j&i<j+n|i<=n*3-j-1&i++>n*2-j-1?'*':' ';return s;} is shorter [120 bytes] (and also gets rid of the brackets by putting everything inside the for-loop. Here is a TIO-link to show it works. Also, feel free to add this (or your own) TIO-link to your answer. :) \$\endgroup\$ Jun 14, 2017 at 7:37
  • 1
    \$\begingroup\$ @KevinCruijssen I didn't know that TIO could handle C# code! I added the WriteLine in the code because the OP asked to output the big X, not just to return it, so I felt that the outputting of the X (by calling the WriteLine method) should be part of the code. Nonetheless, I'm still not used to the rules of code-golf, and I don't know what licenses I can take when writing code. I have just seen that some of the other answers here print the X in the code, and some others print it in the footer. What is the valid approach in this case? \$\endgroup\$
    – Charlie
    Jun 14, 2017 at 7:50
  • 1
    \$\begingroup\$ Usually returning a string as well as using a function instead of a program is allowed by default, unless stated otherwise. Also, in the question it states "Output may be print out or a string or array of strings", so returning a string is allowed. :) Oh, and one last thing you can golf: j<n*2+1 can be j<=n*2. I've also created a Java 8 port of your answer with the same byte-count, crediting your amazing answer of course. \$\endgroup\$ Jun 14, 2017 at 7:53
3
\$\begingroup\$

Haskell, 88 87 86 bytes

-1 thanks to @Laikoni

(!)=replicate
x n=[zipWith max(reverse m)m|m<-[i!' '++n!'*'++(n*2-i)!' '|i<-[0..n*2]]]

Try it online!

\$\endgroup\$
1
  • 1
    \$\begingroup\$ zipWith max m(reverse m) can be shortened to zipWith max(reverse m)m. This is the same as zipWith max=<<reverse$m, and then m can be inlined: Try it online! \$\endgroup\$
    – Laikoni
    Jun 13, 2017 at 17:38
2
\$\begingroup\$

Jelly, 24 23 16 bytes

Ḥ‘Ḷ⁸+þṬ+Ṛ$a”*o⁶Y

Try it online!

\$\endgroup\$
2
\$\begingroup\$

MATLAB, 153 126 bytes (17.6%↓)

Thanks to @LuisMendo's comment, function disp() can output chars without single quotes, thus I could prevent using fprintf with formats and omit a few bytes. Besides, his comment reminds me that I need use char(32) to present a space rather than char(0) (null).

n=input('')
r=2*n+1
c=3*n
a=0
for i=0:n-1
a=a+[zeros(r,i),diag(1:r),zeros(r,c-r-i)];
end
a((a+flipud(a))>0)=10
disp([a+32 ''])

Try it online!

MATLAB, 153 bytes

n=input('')
r=2*n+1
c=3*n
a=0
for i=0:n-1 
a=a+[zeros(r,i),diag(1:r),zeros(r,c-r-i)];
end
a((a+flipud(a))>0)=42
fprintf([repmat('%c',1,c),'\n'],char(a)')

Result example: n=10

**********          **********
 **********        ********** 
  **********      **********  
   **********    **********   
    **********  **********    
     ********************     
      ******************      
       ****************       
        **************        
         ************         
          **********          
         ************         
        **************        
       ****************       
      ******************      
     ********************     
    **********  **********    
   **********    **********   
  **********      **********  
 **********        ********** 
**********          **********
\$\endgroup\$
0
2
\$\begingroup\$

Python 2, 93 90 89 83 bytes

-3 bytes thanks to Leaky Nun
-1 byte thanks to Zachary T
-6 bytes thanks to xnor

n=input()
x=n*'*'+n*'  '
exec"print`map(max,x,x[::-1])`[2::5];x=' '+x[:-1];"*(n-~n)

[Try it online!][TIO-j3xwsktf]

Starts with a string like '*** ' for n=3, applying map/max to pick the * over the spaces for each position, then append a space and remove the last character from the string and do this all again.

\$\endgroup\$
3
  • \$\begingroup\$ 90 bytes \$\endgroup\$
    – Leaky Nun
    Jun 13, 2017 at 14:33
  • \$\begingroup\$ Can't you replace n*2*' ' with n*' '? \$\endgroup\$
    – Adalynn
    Jun 14, 2017 at 16:55
  • \$\begingroup\$ The map(max can be done directly without a zip. Also, n*2+1 is n-~n. \$\endgroup\$
    – xnor
    Jun 15, 2017 at 1:21
1
\$\begingroup\$

Haskell, 70 bytes

f n=[[last$' ':['*'|y<-[1..n],(c-n-y)^2==r^2]|c<-[1..3*n]]|r<-[-n..n]]

Try it online!

Outputs a list of strings.

For each position of row r, column c, uses a formula to determine whether it falls in one of the two diagonal bands and so is *.

\$\endgroup\$
1
\$\begingroup\$

Javascript (ES2017), 155 157 bytes

n=>[...e=[...Array(n+1)].map((a,i)=>[...d=((b=''.padEnd(n))[c='slice'](i)+'*'.repeat(n)+b[c](0,i))[c](n/2)].reverse().join``+d[c](n%1)),...e.reverse()[c](1)]

Returns an array of strings. I perform operations on arrays then mirror it. This could probably be optimized with matrices like the other answers, but I wanted to be unique.

Edit: As pointed out by Neil, for even values of n, the center line was not n wide, so I added a modulus to detect even/odd when slicing the column.

n=5
['*****     *****',
 ' *****   ***** ',
 '  ***** *****  ',
 '   *********   ',
 '    *******    ',
 '     *****     ',
 '    *******    ',
 '   *********   ',
 '  ***** *****  ',
 ' *****   ***** ',
 '*****     *****']

Ungolfed

n => {
  e = [...Array(n+1)].map((a, i) => {   // Create and iterate over array with n+1 elements
    b = ''.padEnd(n)                    // String of n spaces
    d = (b.slice(i) + '*'.repeat(n) + b.slice(0, i)).slice(n/2) // Create row string
    return [...d].reverse().join`` + d.slice(1) // Mirror and combine row horizontally
  })
  return [...e,...e.reverse().slice(1)] // Mirror and combine vertically
}

Quadrant

n=5
   *****
  ***** 
 *****  
*****   
****    
***     

Mirrored Horizontally

n=5
*****     *****
 *****   ***** 
  ***** *****  
   *********   
    *******    
     *****     

Mirrored Vertically

n=5
*****     *****
 *****   ***** 
  ***** *****  
   *********   
    *******    
     *****     
    *******    
   *********   
  ***** *****  
 *****   ***** 
*****     *****
\$\endgroup\$
1
  • \$\begingroup\$ This produces incorrect output for even n - the centre line is not n wide. \$\endgroup\$
    – Neil
    Jun 17, 2017 at 0:28
1
\$\begingroup\$

Java 10, 119 118 111 bytes

n->{var r="";for(int i=0,j;i<n-~n;i++,r+="\n")for(j=0;j<n*3;r+=j>=i&j<i+n|j<n*3-i&++j>n*2-i?"*":" ");return r;}

Port from @CarlosAlejo's amazing C# answer, after I helped him golf a few things. So make sure to upvote him as well!
-4 bytes thanks to @ceilingcat.

Try it here.

\$\endgroup\$
0
0
\$\begingroup\$

Mathematica, 148 bytes

T=Table;(a=Join[T[T["*",i],{i,(n=#)+2,2n,2}],T[Join[t=T["*",n],T[" ",y],t],{y,1,n,2}]];Column[Row/@Join[Reverse@a,{T["*",n]},a],Alignment->Center])&
\$\endgroup\$
0
\$\begingroup\$

R, 102 bytes

Code:

n=scan();x=matrix(" ",M<-3*n,N<-2*n+1);for(i in 1:N)x[c(i-1+1:n,M+2-i-1:n),i]="*";cat(x,sep="",fill=M)

Test:

> n=scan();x=matrix(" ",M<-3*n,N<-2*n+1);for(i in 1:N)x[c(i-1+1:n,M+2-i-1:n),i]="*";cat(x,sep="",fill=M)
1: 10
2: 
Read 1 item
**********          **********
 **********        ********** 
  **********      **********  
   **********    **********   
    **********  **********    
     ********************     
      ******************      
       ****************       
        **************        
         ************         
          **********          
         ************         
        **************        
       ****************       
      ******************      
     ********************     
    **********  **********    
   **********    **********   
  **********      **********  
 **********        ********** 
**********          **********
\$\endgroup\$
0
\$\begingroup\$

CJam, 24 bytes

{:T2*){S*T'**+}%_W%..e>}

This is a block that takes a number from the stack and outputs a list of lines to the stack.

Explanation:

{                        e# Stack:           | 2
 :T                      e# Store in T:      | 2, T=2
   2*                    e# Multiply by 2:   | 4
     )                   e# Increment:       | 5
      {                  e# Map over range:  | [0
       S                 e#   Push space:    | [0 " "
        *                e#   Repeat string: | [""
         T               e#   Push T:        | ["" 2
          '*             e#   Push char '*': | ["" 2 '*
            *            e#   Repeat char:   | ["" "**"
             +           e#   Concatenate:   | ["**"
              }%         e# End:             | ["**" " **" "  **" "   **" "    **"]
                _        e# Duplicate:       | ["**" " **" "  **" "   **" "    **"] ["**" " **" "  **" "   **" "    **"]
                 W%      e# Reverse:         | ["**" " **" "  **" "   **" "    **"] ["    **" "   **" "  **" " **" "**"]
                   ..e>  e# Overlay:         | ["**  **" " ****" "  **" " ****" "**  **"]
                       } e# End
\$\endgroup\$
0
\$\begingroup\$

Python 2, 110 bytes

x=a=0
n=c=input()
while x<2*n+1:
    print ' '*a+'*'*n+' '*c+'*'*(2*n-2*a-c)
    x+=1
    a=n-abs(n-x)
    c=max(0, n-2*a)

This program breaks each line into 4 parts, first spaces, first stars, second spaces and then second stars. For each horizontal line of the X it calculates how many stars or spaces are needed for each of the 4 sections of the line, then constructs and prints that string.

\$\endgroup\$
0
\$\begingroup\$

Retina, 144 bytes

.+
 $&$* $&$* $&
 
$`#$'¶
¶\d+$

( *)#( *)(\d+)
$1$3$**$2#$3$* #$2$3$**$1
( +)(\*+)( *)(# +#)\3\2\3 +
$3$2$1$4$1$2$3
+` (# +#)
$1 
+` #...
#
##

Try it online! Explanation:

.+
 $&$* $&$* $&

Add 2n+1 spaces before the input value (one for each output line).

$`#$'¶

Replace each space with a # and collect the results. This gives a diagonal line of #s, space padded on both sides, with the input value suffixed.

¶\d+$

Delete the original input value, as we now have a copy on each line.

( *)#( *)(\d+)
$1$3$**$2#$3$* #$2$3$**$1

Build up two diagonal lines of n *s, with a separator column of n spaces wrapped in a pair of #s.

( +)(\*+)( *)(# +#)\3\2\3 +
$3$2$1$4$1$2$3

On those lines where the *s are nearer the middle, swap the two halves around. This gives an appearance resembling > | | <.

+` (# +#)
$1 

Move the | |s as far left as they will go, giving a sort of >> > < appearance.

+` #...
#

For each space between the #s, delete the three following characters. This joins the > < into an X.

##

Delete the now unnecessary #s.

\$\endgroup\$
0
\$\begingroup\$

05AB1E, 16 bytes

ENI>1})¦'*…×82SΛ

Try it online.

Explanation:

E      # Loop N in the range [1, (implicit) input]:
 N     #  Push loop-index N
  I>   #  Push the input, and increase it by 1
    1  #  Push 1
})     # After the loop: wrap all values on the stack into a list
  ¦    # And remove the very first 1
'*    '# Push "*"
…×82S  # Push "×82" as list: ["×",8,2]
Λ      # Use the Canvas builtin with these three arguments
       # (after which it is output implicitly)

Canvas explanation:

The Canvas builtin takes three arguments:
1. The lengths of the lines to 'draw', which in this case is the list we generate at the start with the loop. For an input \$n=3\$, the list will look like this: \$[4,1,2,4,1,3,4,1]\$ (or more in general: for sequence \$x_n\$ in \$[2,n]\$, the list will be \$[n+1,1,x_1,n+1,1,x_2,n+1,1,x_3,...]\$).
2. The string to 'draw', which in this case is "*".
3. The directions, which in this case is ["×",8,2]. These will be the directions [cross, reset-to-origin, →].

With these arguments, it will draw as follows (let's take the \$n=3\$ as example again):

Draw an X-shaped cross of character "*" with arms of length 4:
*     *
 *   *
  * *
   *
  * *
 *   *
*     *

Reset back to the origin (8), and draw 2-1 characters "*" in direction 2 (→):
(NOTE: The origin is the center of this first cross.)
*     *
 *   *
  * *
   **
  * *
 *   *
*     *

Draw an X-shaped cross of character "*" with arms of length 4 again:
**    **
 **  **
  ****
   **
  ****
 **  **
**    **

Reset back to the origin (8), and draw 3-1 characters "*" in direction 2 (→):
**    **
 **  **
  ****
   ***
  ****
 **  **
**    **

Draw an X-shaped cross of character "*" with arms of length 4 again:
***   ***
 *** ***
  *****
   ***
  *****
 *** ***
***   ***

See this 05AB1E tip of mine for a more in-depth explanation of the Canvas builtin.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.