This challenge uses the '+' character

31

1

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!

Comrade SparklePony

Posted 2017-04-11T15:14:26.920

Reputation: 5 784

I assume trailing spaces on each line are allowed so that the result is square, right? – Luis Mendo – 2017-04-11T15:29:27.697

@LuisMendo Yes, that is fine. – Comrade SparklePony – 2017-04-11T15:31:40.980

Related. – Neil – 2017-04-11T19:29:57.700

3"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. – Wossname – 2017-04-13T06:43:09.987

@Wossname The length of each 'spoke' of the plus sign is equal to n. The + in the middle is the center, but it is considered 1 away from the center. If something is next to it, it is 2 away from the center. Anything next to that is 3 away. And so on. Try running some existing programs. – Comrade SparklePony – 2017-04-13T11:26:27.620

6It would have been a lot less confusing if the centre were 0 away from itself. – OrangeDog – 2017-04-13T13:45:01.933

Answers

45

Charcoal, 5 bytes

P+×+N

Try it online!

fergusq

Posted 2017-04-11T15:14:26.920

Reputation: 4 867

23What even is this language? – James – 2017-04-11T19:40:42.303

@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 P+ = cross). – fergusq – 2017-04-11T20:12:40.070

Are those not multibyte characters? – Petah – 2017-04-12T02:36:11.237

3

@Petah Charcoal uses a custom codepage.

– ASCII-only – 2017-04-12T04:45:30.840

@fergusq You might be mixing Charcoal up with Turtlèd :P, Charcoal isn't really a turtle graphics language

– ASCII-only – 2017-04-12T04:48:55.990

28

Python 2, 53 bytes

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

Try it online!

Dennis

Posted 2017-04-11T15:14:26.920

Reputation: 196 637

13

JavaScript (ES6), 67 65 63 60 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>

Shaggy

Posted 2017-04-11T15:14:26.920

Reputation: 24 623

1I'm not entirely sure, but I think you can replace the "\n" with two backticks and a literal newline between them – user41805 – 2017-04-11T15:54:47.723

Thanks, @KritixiLithos; don't know why I didn't think of that sooner myself. – Shaggy – 2017-04-11T16:04:46.587

1It looks like you could probably save a byte by aliasing repeat, e.g. a='repeat',v=..... and \ `[a]` – Marie – 2017-04-11T17:12:24.190

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. – Shaggy – 2017-04-11T17:22:55.563

I see. I did think it would save a bit more but it looks like one byte. An easy comparison is basically a='repeat',[a][a][a] vs .repeat.repeat.repeat, 20 vs 21 respectively. – Marie – 2017-04-11T18:07:55.257

Just tried it myself now quickly, @Marie, but the best I could manage was to match the current byte count. I've included them as alternatives above in case someone can see something I might have missed. – Shaggy – 2017-04-11T18:12:31.673

This was how I did it, minus the line breaks x=>(a='repeat',v=(` `[a](--x)+`+`)[a](x))+`+`[a](x*2+1)+``+v – Marie – 2017-04-11T19:16:46.563

2x=>(v=(` `[r='repeat'](--x)+`+<newline>`)[r](x))+`+`[r](x*2+1)+`<newline>`+v – user2428118 – 2017-04-12T15:40:00.000

Sweet! Thanks, @user2428118. Guess I couldn't see the wood for the trees! – Shaggy – 2017-04-12T15:49:02.140

11

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: ['  +  ';
                '  +  ';
                '+++++';
                '  +  ';
                '  +  ']

Luis Mendo

Posted 2017-04-11T15:14:26.920

Reputation: 87 464

8

Charcoal, 16 13 bytes

Nα×+α←↑×+α‖O↘

Try it online!

Uses a different approach from the other Charcoal answer.

Explanation

Nα                       # 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:

  +
  +
+++

‖O↘                      # 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).

user41805

Posted 2017-04-11T15:14:26.920

Reputation: 16 320

Does Charcoal have its own code page? Many of those characters are multiple bytes in UTF-8. – TRiG – 2017-04-12T10:18:52.413

@TRiG Yes, it does!

– user41805 – 2017-04-12T10:25:28.927

8

Shakespeare Programming Language, 749 743 666 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!

With added newlines:

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;

NieDzejkob

Posted 2017-04-11T15:14:26.920

Reputation: 4 630

"If not,let us return to Scene III." -1; breaks fourth wall :P – Jakob – 2017-08-14T20:14:00.723

7

Jelly, 11 bytes

ṬŒB»þ`ị⁾+ Y

Try it online!

Dennis

Posted 2017-04-11T15:14:26.920

Reputation: 196 637

4fingers crossed :-P – Luis Mendo – 2017-04-11T15:48:59.337

6

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@@@(...).

Martin Ender

Posted 2017-04-11T15:14:26.920

Reputation: 184 808

1Didn't know Print could be used like that. – ngenisis – 2017-04-12T17:34:14.453

6

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));}

Quentin

Posted 2017-04-11T15:14:26.920

Reputation: 1 187

6

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

Riley

Posted 2017-04-11T15:14:26.920

Reputation: 11 345

+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.

– seshoumara – 2017-04-12T09:22:24.723

6

Ruby, 41 40 bytes

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

Try it online!

Ventero

Posted 2017-04-11T15:14:26.920

Reputation: 9 842

5

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.

AdmBorkBork

Posted 2017-04-11T15:14:26.920

Reputation: 41 581

5

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.

Martin Ender

Posted 2017-04-11T15:14:26.920

Reputation: 184 808

5

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

Blab

Posted 2017-04-11T15:14:26.920

Reputation: 451

5

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

xnor

Posted 2017-04-11T15:14:26.920

Reputation: 115 687

5

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}

previous answer:

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

count

Posted 2017-04-11T15:14:26.920

Reputation: 161

1You 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! – JAD – 2017-04-12T13:06:29.040

1Also, you can save a byte using matrix("",y<-n*2-1,y) – JAD – 2017-04-12T13:07:49.547

1a[n,]=a[,n]="x" works too, saving some more bytes. – JAD – 2017-04-12T13:08:54.907

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 – rturnbull – 2017-04-14T10:08:34.373

4

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!

Keerthana Prabhakaran

Posted 2017-04-11T15:14:26.920

Reputation: 759

1

Save 4 bytes like this: TIO

– math junkie – 2017-04-11T16:35:39.927

4

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

Dada

Posted 2017-04-11T15:14:26.920

Reputation: 8 279

4

05AB1E, 15 14 12 bytes

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

Try it online!

-2 thanks to Emigna.

Magic Octopus Urn

Posted 2017-04-11T15:14:26.920

Reputation: 19 422

1You could do F'+}¹·<×)û.c for 12. – Emigna – 2017-04-11T20:22:37.887

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. – Thomas Ward – 2017-04-12T04:41:18.967

@ThomasWard: Good catch! I corrected the link. – Emigna – 2017-04-12T06:35:57.177

F'+}¹×û)û.c for 11 bytes. – Grimmy – 2019-12-16T22:00:15.413

3

Python 2, 65 bytes

lambda n:('g+\n'*~-n+'+'*~-(2*n)+'\ng+'*~-n).replace('g',' '*~-n)

Try it Online!

math junkie

Posted 2017-04-11T15:14:26.920

Reputation: 2 490

3

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

aditsu quit because SE is EVIL

Posted 2017-04-11T15:14:26.920

Reputation: 22 326

3

Octave, 36 31 bytes

Inspired by @LuisMendo 's MATL answer.

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

Try it online!

Previous answer:

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

Try it online!

rahnema1

Posted 2017-04-11T15:14:26.920

Reputation: 5 435

2

V, 19 18 15 bytes

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

Àé r+À«Ä.MgJxÒ+

Try it online!

user41805

Posted 2017-04-11T15:14:26.920

Reputation: 16 320

Try it online! – nmjcman101 – 2017-04-11T15:57:55.820

2

JS (ES6), 88 74 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>

programmer5000

Posted 2017-04-11T15:14:26.920

Reputation: 7 828

1I'm not entirely sure, but I think you can replace the "\n" with two backticks and a literal newline between them – user41805 – 2017-04-11T15:54:35.897

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? – Shaggy – 2017-04-11T16:44:19.563

2

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];

Jörg Hülsermann

Posted 2017-04-11T15:14:26.920

Reputation: 13 026

1You 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. – user59178 – 2017-04-12T08:38:28.710

@user59178 I could not understand what you exactly mean – Jörg Hülsermann – 2017-04-12T09:50:44.423

1for(;$i<$c=-1+2*$m=$argn;)echo"\n".str_pad("+",$c," +"[$m==++$i],2); – user59178 – 2017-04-12T12:00:39.893

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) – Titus – 2017-08-14T17:47:28.993

2

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[0].repeat(n-1))+a[1]+s+`
`)([r(` +`),r(`++`)])

Neil

Posted 2017-04-11T15:14:26.920

Reputation: 95 035

2

MUMPS, 48 50 53 bytes

F i=1-n:1:n-1 W ! F j=1-n:1:n-1 W $C(i&j*-11+43)

mumpsimus

Posted 2017-04-11T15:14:26.920

Reputation: 21

Welcome to PPCG! – Martin Ender – 2017-04-11T21:38:50.330

2

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"

Joey

Posted 2017-04-11T15:14:26.920

Reputation: 12 260

2

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

idrougge

Posted 2017-04-11T15:14:26.920

Reputation: 641

2

Brain-Flak, 216 + 1 = 217 bytes

+1 bytes from the -A flag

([{}]())(()()){<>(((((()()()()()){})){}()){}())<>(({}[()])<({}<(({})){({}()<(({}<<>(({}<(({})<>)>)<>)<>>)<{({}()<(((((()()){}){}){}){})>)}{}>)>)}{}>){(<{}(({}<<>({}<({}<>)>)>)<(({}){}){({}()<(({}))>)}{}>)>)}{}>)}{}{}

Try it online!

Explanation to come

0 '

Posted 2017-04-11T15:14:26.920

Reputation: 3 439

2

Japt, 30 26 24 bytes

23 bytes of code, +1 for the -R flag.

Saved 4 bytes thanks to @ETHproductions!

V=U+´UVǦU?SpU +'+:'+pV

Try it online!

Oliver

Posted 2017-04-11T15:14:26.920

Reputation: 7 160

I think you can save a bunch by doing V=U+´U at the beginning and removing all those pesky -1s ;-) – ETHproductions – 2017-04-20T20:49:29.167

@ETHproductions Great idea, thanks! I saved another byte by using Ç – Oliver – 2017-04-21T03:43:05.803

And another byte by switching to ¦ – Oliver – 2017-04-21T03:45:48.903

2

GolfScript, 27 bytes

~.(." "*"+"n++*.@2*("+"*n+\

Try it online!

Explanation and Example Execution:

                              # Input: 3
~.(.                          # Eval input, duplicate twice, decrement duplicates
                              # Stack: 3 2 2
    " "*                      # That many spaces
                              # Stack: 3 2 "  "
        "+"n++                # Followed by a + and a newline
                              # Stack: 3 2 "  +\n"
              *.              # Create n of those strings and duplicate it
                              # Stack: 3 "  +\n  +\n" "  +\n  +\n"
                @2*(          # Pull bottom to top, double it, decrement
                              # Stack: "  +\n  +\n" "  +\n  +\n" 5
                    "+"*n+    # That many +s followed by a newline
                              # Stack: "  +\n  +\n" "  +\n  +\n" "+++++\n"
                          \   # Swap last 2 items and implicityly print
                              # Stack: "  +\n  +\n" "+++++\n" "  +\n  +\n"

Pseudo Nym

Posted 2017-04-11T15:14:26.920

Reputation: 181

1

Charcoal, 26 25 bytes

NηA⁻η¹η××η²+P+Mη↙G↑⁺¹×η²+

Try it online!

Explanation:

Nη                   // Take the size as input.
A⁻η¹η                // Set η to η-1.
××η²+                // Print '+' η*2 times.
P+                   // Print '+'
Mη↙                 // Move η steps down to the left.
G↑⁺¹×η²+            // Print '+' η*2+1 times upwards from current position.

Steadybox

Posted 2017-04-11T15:14:26.920

Reputation: 15 798

1

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.

Neil

Posted 2017-04-11T15:14:26.920

Reputation: 95 035

1

Pyke, 14 bytes

t.\+s FQt*\++s

Try it online!

Blue

Posted 2017-04-11T15:14:26.920

Reputation: 26 661

1

J, 21 bytes

' +'{~+./~(0=}.,])i.n

ephemient

Posted 2017-04-11T15:14:26.920

Reputation: 1 601

1

8086 machine code, 57 bytes

00000000  a0 82 00 24 cf 98 48 89  c1 b4 4c e3 20 bf 39 01  |...$..H...L. .9.|
00000010  57 51 5a 52 51 b0 20 89  d1 f3 aa b8 2b 0a ab 59  |WQZRQ. .....+..Y|
00000020  e2 f2 c6 05 24 59 01 c9  b4 09 5a cd 21 41 b0 2b  |....$Y....Z.!A.+|
00000030  cd 29 e2 fa 4a cd 21 c3  0a                       |.)..J.!..|
00000039

Takes a number (one digit...) as command line argument.
How it works:

            |   use16
a0 82 00    |       mov al, byte [0x82]
24 cf       |       and al, not 0x30
98          |       cbw
48          |       dec ax
89 c1       |       mov cx, ax
b4 4c       |       mov ah, 0x4c
e3 20       |       jcxz a
bf 39 01    |       mov di, s+1
57          |       push di
51          |       push cx
5a          |       pop dx
52          |       push dx
51          |   @@: push cx
b0 20       |       mov al, ' '
89 d1       |       mov cx, dx
f3 aa       |       rep stosb
b8 2b 0a    |       mov ax, 0x0a2b
ab          |       stosw
59          |       pop cx
e2 f2       |       loop @b
c6 05 24    |       mov byte [di], 0x24
59          |       pop cx
01 c9       |       add cx, cx
b4 09       |       mov ah, 0x09
5a          |       pop dx
cd 21       |       int 0x21
41          |   a:  inc cx
b0 2b       |   @@: mov al, '+'
cd 29       |       int 0x29
e2 fa       |       loop @b
4a          |       dec dx
cd 21       |       int 0x21
c3          |       ret
0a          |   s db 0x0a

user5434231

Posted 2017-04-11T15:14:26.920

Reputation: 1 576

1

Rust, 89 bytes

|n|{for i in 1..2*n{if i==n{println!("{:+^1$}","",2*n-1)}else{println!("{:>1$}","+",n)}}}

bearbear2k

Posted 2017-04-11T15:14:26.920

Reputation: 71

1

05AB1E, 5 bytes (non-competing?)

'+90Λ

Try it online!

Erik the Outgolfer

Posted 2017-04-11T15:14:26.920

Reputation: 38 134

4 bytes (and non-competing is no longer a thing) – Kevin Cruijssen – 2019-12-17T09:15:27.203

1

Keg, 39 37 bytes

;(:|:⑬*,\+,
,):⑨⑵;`+`*,
,(:|:⑬*,\+,
,

-2 bytes using built-ins

Try it online!

This attempt prints the isolated +s first, then the big row of +s then the final isolated +s.

Lyxal

Posted 2017-04-11T15:14:26.920

Reputation: 5 253

1

Wren, 67 bytes

Fn.new{|n|(1...2*n).map{|i|i==n?"+"*(n+~-n):" "*~-n+"+"}.join("
")}

Try it online!

Explanation

Fn.new{|n|                                                      // New anonymous function with parameter n
          (1...2*n).map{|i|                                     // Foreach 1 -> 2n-1:
                           i==n?                                // If i equals n:
                                "+"*(n+~-n)                     // Return "+" 2n-1 times
                                           :" "*~-n             // Otherwise return space n-1 times
                                                   +"+"         // Add a trailing "+"
                                                       }.join("
")}                                                             // Join with newline

user85052

Posted 2017-04-11T15:14:26.920

Reputation:

0

Common Lisp, SBCL, 69 bytes

(format t"~@?~@?~@?+
~@*~@?""~v@{~:*~v@t+
~}"(1-(read))"~1@*~v@{+~}")

Explanation

format        ;printing function
~@?           ;execute current argument as format string 
~@*           ;go to first argument in list, to reuse "~v@{~:*~v@t+
              ;~}"
~v@{~}        ;loop n times, where n is current argument
~:*           ;go back one argument - to reuse (1-(read))
~v@t          ;add n spaces where n is current argument
              ;if we were sure that we start on new line we could
              ;use ~vt, which moves to nth column
(1-(read))    ;take input and subtract 1 from it
~1@*          ;move to second argument, to reuse (1-(read))

"~@?~@?~@?+   ;main format string - calls others
~@*~@?"       ;prints one "+" and one newline
"~v@{~:*~v@t+ ;outputting input-1 lines of "+"s
~}"           ;preceded by correct amount of spaces
"~1@*~v@{+~}" ;outputting input-1 pluses. We do it two times
              ;and then add one + at the end. This way there
              ;is no need for argument like: (1-(* 2 INPUT))
              ;which would make me need a variable keeping INPUT

Ideas for improvement are welcomed.

user65167

Posted 2017-04-11T15:14:26.920

Reputation:

0

Pyth, 24 bytes

+J*+++K*dQ\+Kb/Q2*\+hyQJ

Try it online!

chromaticiT

Posted 2017-04-11T15:14:26.920

Reputation: 211

0

Perl 5, 43 + 1 (-n) = 44 bytes

$,="+
";say@q=($"x--$_)x$_,'+'x(2*$_),@q,''

Try it online!

Independently came up with pretty much the same method as @Dada, but got it down by 1 byte.

Xcali

Posted 2017-04-11T15:14:26.920

Reputation: 7 671

0

Excel, 86 bytes

=REPT(REPT(" ",A1-1)&"+
",A1-1)&REPT("+",2*A1-1)&"
"&REPT(REPT(" ",A1-1)&"+
",A1-1)

Wernisch

Posted 2017-04-11T15:14:26.920

Reputation: 2 534

0

J, 17 bytes

Anonymous tacit prefix function

' +'{~0=*/~@i:@<:

Try it online!

For example for 3:

<: decrement; 2

i: steps; [-2,-1,0,1,2]

*/~ times table; [[4,2,0,-2,-4],[2,1,0,-1,-2],[0,0,0,0,0],[-2,-1,0,1,2],[-4,-2,0,2,4]]

0= indicate where zero; [[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]]

" +"{~ use that to index into " +"; [" + "," + ","+++++"," + "," + "]

Adám

Posted 2017-04-11T15:14:26.920

Reputation: 37 779

0

PowerShell, 47 bytes

param($n)($x=,(' '*--$n+'+')*$n)
'+'+'++'*$n
$x

Try it online!

This one is shorter than 48 bytes ¯\_(ツ)_/¯

mazzy

Posted 2017-04-11T15:14:26.920

Reputation: 4 832