# This challenge uses the '+' character

Your task: given a number n, generate a '+' sign that is n characters away from its center. If this is confusing, check out the test cases.

Standard methods of input: output must be a string or printed. Standard loopholes apply.

Input: 1
Output: +           ] 1 away from center +.

Input: 2
Output:  +          ] 2 away from center +.
+++         ] 1 away from center +.
+

Input: 3
Output:   +         ] 3 away from center +.
+
+++++
+
+


This is , so shortest code wins!

• I assume trailing spaces on each line are allowed so that the result is square, right? Apr 11, 2017 at 15:29
• @LuisMendo Yes, that is fine. Apr 11, 2017 at 15:31
• – Neil
Apr 11, 2017 at 19:29
• "generate a '+' sign that is n characters away from its center" -- I don't understand this part. What center are you referring to? How can something be eccentric to itself? Please clarify. Apr 13, 2017 at 6:43
• It would have been a lot less confusing if the centre were 0 away from itself. Apr 13, 2017 at 13:45

# Charcoal, 5 bytes

Ｐ+×+Ｎ


Try it online!

• What even is this language? Apr 11, 2017 at 19:40
• @DJMcMayhem Basically you can do turtle graphics ASCII art with it. It has a lot of handy builtins for rendering different kind of ASCII shapes (like Ｐ+ = cross). Apr 11, 2017 at 20:12
• Are those not multibyte characters? Apr 12, 2017 at 2:36
• @Petah Charcoal uses a custom codepage. Apr 12, 2017 at 4:45
• @fergusq You might be mixing Charcoal up with Turtlèd :P, Charcoal isn't really a turtle graphics language Apr 12, 2017 at 4:48

# Python 2, 53 bytes

n=2*input()-1;C='+'.center
for c in C(n):print C(n,c)


Try it online!

# JavaScript (ES6), 67656360 59 bytes

x=>(v=( [r=repeat](--x)++
)[r](x))++[r](x*2)++
+v;

• 2 bytes saved by replacing two occurrences of x-1, the first with --x and the second with x.
• 2 bytes saved thanks to Kritixi Lithos, replacing "\n" with [newline].
• 3 bytes saved thanks to user2428118, finally helping me to figure out a way to alias the repeat in a way that reduced the size. (With honourable mention to Marie for her efforts, too)
• 1 byte saved indirectly thanks to Herman.

## Try It

f=
x=>(v=( [r=repeat](--x)++
)[r](x))++[r](x*2)++
+v;
oninput=_=>o.innerText=f(+i.value)
o.innerText=f(i.value=3)
<input id=i min=1 type=number><pre id=o>

• I'm not entirely sure, but I think you can replace the "\n" with two backticks and a literal newline between them Apr 11, 2017 at 15:54
• Thanks, @KritixiLithos; don't know why I didn't think of that sooner myself. Apr 11, 2017 at 16:04
• It looks like you could probably save a byte by aliasing repeat, e.g. a='repeat',v=..... and  [a] Apr 11, 2017 at 17:12
• Thanks, @Marie; I had tried aliasing repeat() but my first few attempts came out 2 or 3 bytes bigger so I abandoned it! I'll have another look at it when I get back in front of a computer. Apr 11, 2017 at 17:22
• x=>(v=( [r='repeat'](--x)++<newline>)[r](x))++[r](x*2+1)+<newline>+v Apr 12, 2017 at 15:40

# MATL, 11 bytes

tZv=&+g43*c


Try it online!

### Explanation with example

Consider n = 3.

t     % Implicitly input n. Duplicate
% STACK: 3, 3
Zv    % Symmetric range
% STACK: 3, [1 2 3 2 1]
=     % Equal, element-wise
% STACK: [0 0 1 0 0]
&+    % All pair-wise additions. Gives a 2D array
% STACK: [0 0 1 0 0;
0 0 1 0 0;
1 1 2 1 1;
0 0 1 0 0;
0 0 1 0 0]
g     % Logical: convert non-zero to one
% STACK: [0 0 1 0 0;
0 0 1 0 0;
1 1 1 1 1;
0 0 1 0 0;
0 0 1 0 0]
43*   % Multiply by 43 (ASCII for '+'), element-wise
% STACK: [ 0  0 43  0  0;
0  0 43  0  0;
43 43 43 43 43;
0  0 43  0  0;
0  0 43  0  0]
c     % Convert to char. Char 0 is displayed as space. Implicitly display.
% STACK: ['  +  ';
'  +  ';
'+++++';
'  +  ';
'  +  ']


# Charcoal, 16 13 bytes

Ｎα×+α←↑×+α‖Ｏ↘


Try it online!

Uses a different approach from the other Charcoal answer.

### Explanation

Ｎα                       # Take input and store it in variable α
×+α                       # α times write a +
←                         # Go left
↑×+α                      # α times write a + upwards


Now the top left corner is complete, it will look something like this:

  +
+
+++

‖Ｏ↘                      # Reflect-overlap it in a SE direction


The last step is the key to this program, it uses the top-left part of the plus to generate the rest of the plus by reflecting it in the southeast direction (rightwards and downwards).

• Does Charcoal have its own code page? Many of those characters are multiple bytes in UTF-8.
– TRiG
Apr 12, 2017 at 10:18
• @TRiG Yes, it does! Apr 12, 2017 at 10:25
• This can be simplified to ×+Ｎ‖Ｏ<.
– Neil
Oct 8, 2020 at 21:40

# Shakespeare Programming Language, 749743666 625 bytes

N.Puck,.Page,.Ford,.Ajax,.Act I:.Scene I:.[Enter Puck and Ford]Puck:Listen tothy!Ford:You is the difference betweena cat I.Scene V:.[Exeunt][Enter Page and Ajax]Ajax:You is the difference betweena cat Ford.Scene X:.Page:You is the product ofPuck I.Is you as big as zero?If soyou is the sum oftwice the sum oftwice twice the sum ofa big big cat a cat a cat a cat.If notyou big big big big big cat.Speak thy!Ajax:You is the sum ofyou a cat.Is you worse Ford?If soLet usScene X.Page:You is twice the sum ofa big big cat a cat.Speak thy![Exit Page][Enter Puck]Ajax:You is the sum ofyou a cat.Is you worse Ford?If soLet usScene V.


Try it online!

N.
Puck,.
Page,.
Ford,.
Ajax,.
Act I:.
Scene I:.
[Enter Puck and Ford]
Puck:Listen tothy!
Ford:You is the difference betweena cat I.
Scene V:.
[Exeunt]
[Enter Page and Ajax]
Ajax:You is the difference betweena cat Ford.
Scene X:.
Page:You is the product ofPuck I.Is you as big as zero?
If soYou is the sum ofTwice the sum ofTwice twice the sum ofA big big cat a cat a cat a cat.
If notyou big big big big big cat.Speak thy!
Ajax:You is the sum ofyou a cat.Is you worse Ford?If soLet usScene X.
Page:You is twice the sum ofa big big cat a cat.Speak thy!
[Exit Page]
[Enter Puck]
Ajax:You is the sum ofyou a cat.Is you worse Ford?If soLet usScene V.


Golfed 6 bytes because scene numbers don't have to be consecutive. Golfed some more bytes by applying the tips in the new answers to the Shakespeare tips question, though these golfs aren't reflected in the explanation.

## (Slightly outdated) explaination

SPL is an esolang designed to look like Shakespeare plays. Positive nouns have the value of 1 (here cat is used) and negative nouns have the value of -1 (none were used but pig is one of them). Adjectives modify a constant by multiplying it by 2.

N.


Everything until the first dot is the title and doesn't matter.

Puck,.                           row counter
Page,.                           column counter
Ford,.                           input
Ajax,.                           temp


The characters are integer variables, each of them also has a stack but I did not need to use that feature.

Act I:.
Scene I:.


Acts and scenes are used as goto labels

[Enter Puck and Ford]


It's only useful if exactly two characters are on the stage at the same time.

Puck:Listen to thy heart!


Reads a number and makes Ford remember it.

Ford:You is the difference between a cat and I.


As you can see Engrish is valid in SPL. This makes Puck's value "the different between a cat and I". But what does it mean? cat is a positive noun, so it's Puck = 1 - Ford.

Scene II:.
[Exeunt]


Exeunt is just a plural of "exit", and without arguments means that everyone on the stage exits.

[Enter Page and Ajax]
Ajax:You is the difference between a cat and Ford.


It's also Page = 1 - Ford but it's spoken by a different actor so I would be wrong. Since it's a loop, I can't just copy the value of Puck.

Scene III:.
Page:You is the product of Puck and I.


Pretty straightforward by now. Ajax = Puck * Page.

Is you as big as zero?


"as [adj] as" is the == operator.

If so,you is the sum of the sum of the sum of a big big big big big cat and a big big big cat and a big cat and a cat.


If Ajax == 0... "cat" is 1, "big cat" is 2, "big big cat" is 4 and so on. After substituting the simple constants we get "the sum of the sum of the sum of 32 and 8 and 2 and 1" -> "the sum of the sum of 40 and 2 and 1" -> "the sum of 42 and 1" -> "43", which is the ASCII for +.

If not,you fat fat fat fat fat cat.


else it's just "fat fat fat fat fat cat", so Ajax gets the value of 32, the ASCII for a space.

Speak thy mind!


This is the command for outputting a character.

Ajax:
You sum you and cat.Is you as big as Ford?If not,let us return to Scene III.


This is a loop construct. "You sum you and cat" increments Page, and if(Page != Ford) goto Scene III. The rest of the program uses the same components, so here is a more readable pseudocode version:

Scene1:
input = [input number];
row = 0 - input + 1;
Scene2:
col = 0 - input + 1;
Scene3:
temp = row * col;
if(temp == 0){
temp = '+';
}else{
temp = ' ';
}

putchar(temp);
Page = Page + 1;
if(Page != Ford) goto Scene3;
Ajax = 10;
putchar(Ajax);
Puck = Puck + 1;
if(Puck != Ford) goto Scene2;

• "If not,let us return to Scene III." -1; breaks fourth wall :P Aug 14, 2017 at 20:14

# Jelly, 11 bytes

ṬŒB»þị⁾+ Y


Try it online!

• fingers crossed :-P Apr 11, 2017 at 15:48

## Mathematica, 39 bytes

Print@@@(CrossMatrix[#-1]"+"/. 0->" ")&


CrossMatrix is a built-in that generates a matrix of the required shape with 1s instead of +s and 0s instead of spaces. If we multiply that matrix by "+", that replaces the 1s with +s while leaving the 0s unchanged (obviously... 0*x = 0 and 1*x = x, right?). Then we replace the zeros manually with spaces using /. 0->" ". Finally, we print each line of the matrix with Print@@@(...).

• Didn't know Print could be used like that. Apr 12, 2017 at 17:34

# C, 69 bytes

Not very interesting... Loops over the square, printing out the appropriate character.

r,c;f(n){for(r=-n;++r<n;puts(""))for(c=-n;++c<n;putchar(r*c?32:43));}


# Ruby, 41 40 bytes

->x{puts k=[?\s*(r=x-1)+?+]*r,?+*r+=x,k}


Try it online!

# Python 2, 52 bytes

n=input()-1
p=(' '*n+'+\n')*n
print p+'++'*n+'+\n'+p


Try it online!

A 53-byte alternative (TIO):

n=input()-1
for c in' '*n+'+'+' '*n:print c*n+'+'+c*n


# GNU sed, 104 99 bytes

-5 thanks to seshoumara
Includes +1 for -r

s/1//;h;:;s/(.*)1/ \12/;t;s/( *2)2(2*)/\1\n\1\2/
t;G;s/1+/&&1/;s/(.*)(\n1*)/&\n\1/;/1/!c+
y/12/++/


Takes input in unary.

Try it online!

s/1//                    # Subtract 1 from input
h                        # Hold onto input
:                        # Start loop
s/(.*)1/ \12/            #   Remove a 1, prepend a space, and append a 2
t                        # Loop until all 1s are 2s
# Start Loop (uses the previous label)
s/( *2)2(2*)/\1\n\1\2/   #   Shift all but the first 2 from the last line to a new line
#   E.g.  "  2"      "  2"
#         "  222" -> "  2"
#                    "  22"
t                        # Loop until all 2s are on their own line
G                        # Append a newline and input
s/1+/&&1/                # Double the number of 1s and append an extra
s/(.*)(\n1*)/&\n\1/      # Copy all of the lines with 2s to the end
/1/!c+                   # If there aren't any 1s print a '+'
y/12/++/                 # Convert all 1s and 2s to +s

• +1 You can save 5 bytes by using s/( *2)2(2*)/\1\n\1\2/ and s/(.*)(\n1*)/&\n\1/ as shown here, for a total score of 99. Apr 12, 2017 at 9:22

R, 54 bytes

Shaving off 7 bytes thanks to @Jarko Dubbeldam:

function(n){a=matrix("",y<-n*2-1,y);a[n,]=a[,n]="x";a}


f=function(n){a=matrix("",n*2-1,n*2-1);a[n,]="x";a[,n]="x";a}

• You don't have to name functions, so function(n){a=matrix("",n*2-1,n*2-1);a[n,]="x";a[,n]="x";a} would be 59 bytes!
Apr 12, 2017 at 13:06
• Also, you can save a byte using matrix("",y<-n*2-1,y)
Apr 12, 2017 at 13:07
• a[n,]=a[,n]="x" works too, saving some more bytes.
Apr 12, 2017 at 13:08
• You can save another 4 bytes by using scan() and making it a program rather than a function: n=scan();a=matrix("",y<-n*2-1,y);a[n,]=a[,n]="+";a Apr 14, 2017 at 10:08

# PowerShell, 48 bytes

param($n)($x=,(" "*--$n+"+")*$n);'+'*(1+2*$n);$x


Try it online!

Takes input $n. Starts by constructing a string of --$n spaces, concatenated with +. That's converted into an array using the comma operator, (newly-decremented) $n times. That array is stored in $x and encapsulated in parens to place a copy on the pipeline.

We then do the middle section, which is + string multiplied out the appropriate number of times. That's left on the pipeline. Finally, we put $x on the pipeline again. Those are all left on the pipeline at program completion, and the implicit Write-Output inserts a newline between elements. # Lua 113, 90 bytes r,w,p=string.rep,io.read(),io.write;s=r(' ',w-1)p(r(s..'+'..'\n',w-1))p(r('+',w*2-1)..'\n')p(r(s..'+'..'\n',w-1))  r,w=string.rep,io.read()d=w*2-1;for a=1,d do print(a~=w and r(' ',w-1)..'+'or r('+',d))end  ## CJam, 23 bytes ri_(S*'++a\2*(*_z..e>N*  Try it online! ### Explanation This feels a bit suboptimal, but the idea is to superimpose the following two grids:  + + + + +   +++++  Which gives the desired result. ri e# Read input and convert to integer N. _( e# Duplicate and decrement. S* e# Get a string of N-1 spaces (indentation of the vertical bar). '++ e# Append a + (the vertical bar). a e# Wrap the line in an array. \2*( e# Swap with the other copy of N and compute 2N-1. * e# Repeat the line that many times. _z e# Duplicate the grid and transpose it. ..e> e# Pairwise maximum between the two grids. This superimposes them. N* e# Join with linefeeds.  # Python 2, 65 bytes lambda n:('g+\n'*~-n+'+'*~-(2*n)+'\ng+'*~-n).replace('g',' '*~-n)  Try it Online! # Perl 5, 45 bytes 44 bytes of code + -p flag. $_=join"+
",@%=($"x--$_)x$_,"+"x($_*2),@%,""


Try it online!

Some similar (but still different) approaches:

48 bytes (47+-p):

$_=join"+"x($_*2-1).$/,(~~($"x--$_."+\n")x$_)x2


50 bytes (49+-n):

$,="+"x($_*2-1).$/;print+(~~($"x--$_."+\n")x$_)x2


# CJam, 17

ri(S*_]'+*_ffe>N*


Try it online

Explanation:

ri(      read n, convert to int and decrement
S*       make a string of n-1 spaces
_]       duplicate it and put the 2 strings in an array
'+*_     join the strings with a '+' and duplicate the result
ffe>     for each pair of characters from the 2 (identical) strings,
get the larger character (results in a matrix)
N*       join the rows with newlines


# Octave, 36 31 bytes

Inspired by @LuisMendo 's MATL answer.

@(n)' +'(((a=1:n*2-1==n)|a')+1)


Try it online!

@(n)' +'(1+((a=padarray(1,n-1))|a'))


Try it online!

# 05AB1E, 1514 12 bytes

F'+}¹·<×)û.c


Try it online!

-2 thanks to Emigna.

• You could do F'+}¹·<×)û.c for 12. Apr 11, 2017 at 20:22
• Your try it online link is bad - it doesn't link to the current revision of the post so it shows "bad output" that doesn't match the test cases above. Apr 12, 2017 at 4:41
• @ThomasWard: Good catch! I corrected the link. Apr 12, 2017 at 6:35
• F'+}¹×û)û.c for 11 bytes. Dec 16, 2019 at 22:00

# Python 2, 60,56 bytes

n=input()-1
z=(' '*n+'+\n')*n
print z+'+'*(2*n+1)+'\n'+z


Try it online!

• -4 bytes - thanks to math junkie!
• Save 4 bytes like this: TIO Apr 11, 2017 at 16:35

# JS (ES6), 8874 73 bytes

x=>(x--,y=y=>(" ".repeat(x)++
).repeat(x),y+"+".repeat(x+x+1)+"\n"+y)


Probably can be golfed more.

Snippetify(x=>(x--,y=y=>(" ".repeat(x)++
).repeat(x),y+"+".repeat(x+x+1)+"\n"+y))
<script src="https://programmer5000.com/snippetify.min.js"></script>
<input type = "number">
<pre data-output></pre>

• I'm not entirely sure, but I think you can replace the "\n" with two backticks and a literal newline between them Apr 11, 2017 at 15:54
• Only seeing this solution now, you beat me by a few minutes. What's the etiquette around here on similar solutions in the same language that are posted within a small window of time? Apr 11, 2017 at 16:44

## JavaScript (ES6), 60 bytes

f=
n=>(r=([s,t])=>(s=s.repeat(n-1))+t+s+
)([r( +),r(++)])
<input type=number min=1 oninput=o.textContent=f(this.value)><pre id=o>

Outputs two trailing newlines. Alternative formulation, also 60 bytes:

n=>(r=a=>(s=a.repeat(n-1))+a+s+
)([r( +),r(++)])


## Batch, 108 bytes

@set p=+
@set l=@for /l %%i in (2,1,%1)do @
%l%call set p= %%p%%
%l%echo %p%
@echo %p: =+%
%l%echo %p%


Note: Line 3 ends in a space.

# PowerShell, 48

Doesn't seem to get shorter than that (and pretty much the same approach as the other solution):

($a=,(' '*($n="$args"-1)+'+')*$n)
'+'+'++'*$n$a


or

($a=(' '*($n="$args"-1)+'+ ')*$n)+'++'*$n+"+$a"


# V, 1918 15 bytes

Golfed 3 bytes thanks to @nmjcman101 by using . and Ò+

Àé r+À«Ä.MgJxÒ+


Try it online!

## REXX, 81 bytes

arg a
b=a*2-1
do i=1 to b
if i=a then say copies('+',b)
else say right('+',a)
end


# PHP, 68 Bytes

for(;$i<$c=-1+2*$m=$argn;)echo"\n".str_pad("+",$c," +"[$m==++$i],2);  83 Bytes for(;$i<($c=($n=$argn)*2-1)**2;)echo$i%$c?"":"\n".!++$k," +"[$k==$n|$i++%$c==$n-1];  • You can save a few bytes by using $m=$argn and pre-incrementing $i rather than post incrementing it. you can also save a byte by moving the $m assignment ot the end and dropping the brackets. Apr 12, 2017 at 8:38 • @user59178 I could not understand what you exactly mean Apr 12, 2017 at 9:50 • for(;$i<$c=-1+2*$m=$argn;)echo"\n".str_pad("+",$c," +"[$m==++$i],2); Apr 12, 2017 at 12:00
• while(++$y<2*$n=$argn)echo"\n",str_pad("+",$n*2-1," +"[$y==$n],2); 66 bytes (and save one more with a physical linebreak) Aug 14, 2017 at 17:47

# MUMPS, 48 5053 bytes

F i=1-n:1:n-1 W ! F j=1-n:1:n-1 W \$C(i&j*-11+43)
`
• Welcome to PPCG! Apr 11, 2017 at 21:38