Make a Spiky Box

31

3

Given two positive integers, W and H, output an ASCII-art box whose border is made of slashes (/ and \) with W "spikes" on the top and bottom edges, and H "spikes" on the left and right edges. The box's interior is filled with spaces.

A "spike" is simply two slashes coming together to form an arrow shape:

/\    \/

/      \
\      /

So the output for W = 4, H = 3 would be

/\/\/\/\
\      /
/      \
\      /
/      \
\/\/\/\/

as there are 4 spikes on the top pointing up, 4 on the bottom pointing down, 3 on the left pointing left, and 3 on the right pointing right.

Here are some other input/output pairs:

W H
[spiky slash box]

1 1
/\
\/

1 2
/\
\/
/\
\/

2 1
/\/\
\/\/

2 2
/\/\
\  /
/  \
\/\/

1 3
/\
\/
/\
\/
/\
\/

3 1
/\/\/\
\/\/\/

2 3
/\/\
\  /
/  \
\  /
/  \
\/\/

3 2
/\/\/\
\    /
/    \
\/\/\/

10 1
/\/\/\/\/\/\/\/\/\/\
\/\/\/\/\/\/\/\/\/\/

10 2
/\/\/\/\/\/\/\/\/\/\
\                  /
/                  \
\/\/\/\/\/\/\/\/\/\/

4 5
/\/\/\/\
\      /
/      \
\      /
/      \
\      /
/      \
\      /
/      \
\/\/\/\/

No lines in the output should have leading or trailing spaces. There may optionally be one trailing newline.

The shortest code in bytes wins.

Calvin's Hobbies

Posted 2017-08-10T04:16:21.780

Reputation: 84 000

Can someone who javascripts make a stack snippet for this?

– FantaC – 2017-12-23T20:17:30.137

Answers

15

Charcoal, 9 bytes

BײNײN/\

Try it online!

Explanation

B           Box
  ײN       Next input as number * 2
      ײN   Next input as number * 2
          /\ With border "/\"

ASCII-only

Posted 2017-08-10T04:16:21.780

Reputation: 4 687

3Of course Charcoal has a built-in for 'draw box' – benzene – 2017-08-10T04:24:43.727

1

@benzene It was somewhat fortunate that he recently added the ability to draw an arbitrary string around the box, but even before then there were answers such as https://codegolf.stackexchange.com/a/120065

– Neil – 2017-08-10T07:37:53.860

1@Neil wait recently? When? (Do I know Charcoal less well thank you do? Haha) – ASCII-only – 2017-08-10T09:26:10.443

@ASCII-only My bad! I got confused because of the change that regressed the cursor positioning. (The change that introduced the arbitrary border string was ca904b0 which was almost a year ago.) – Neil – 2017-08-10T16:45:47.740

@benzene Without the box builtin it's still only 13 bytes: F²«↷P…\/N»‖M¬ (takes input in height, width order). – Neil – 2017-08-11T12:53:04.000

11

MATL, 18 bytes

'\/',iE:]!+)O6Lt&(

Try it at MATL Online!

Explanation

Consider inputs W = 4, H = 3. The code builds the row vectors [1 2 3 4 5 6 7 8] (range from 1 to 2*W) and [1 2 3 4 5 6] (range from 1 to 2*H). Transposing the latter and adding to the former with broadcast gives the matrix

2  3  4  5  6  7  8  9
3  4  5  6  7  8  9 10
4  5  6  7  8  9 10 11
5  6  7  8  9 10 11 12
6  7  8  9 10 11 12 13
7  8  9 10 11 12 13 14

Modular indexing into the string \/ produces the desired result in the matrix border:

/\/\/\/\
\/\/\/\/
/\/\/\/\
\/\/\/\/
/\/\/\/\
\/\/\/\/

To remove the non-border values, we set them to 0 (when interpreted as char it is displayed as space):

/\/\/\/\
\      /
/      \
\      /
/      \
\/\/\/\/

Commented code:

'\/'    % Push this string. Will be indexed into
,       % Do twice
  i     %   Input a number
  E     %   Multiply by 2
  :     %   Range 
]       % End
!       % Transpose
+       % Add
)       % Index
O       % Push 0
6L      % Push [2 -1+1j]. As an index, this means 2:end
t       % Duplicate
&(      % Write 0 into the center rectangle. Implicit display

Luis Mendo

Posted 2017-08-10T04:16:21.780

Reputation: 87 464

8

Python 2, 69 68 bytes

-1 thanks to Kevin Cruijssen

lambda w,h:'/\\'*w+'\n'+'\\%s/\n/%s\\\n'%(('  '*~-w,)*2)*~-h+'\\/'*w

Try it online!

Sisyphus

Posted 2017-08-10T04:16:21.780

Reputation: 1 521

\\%s can become \%s and \\/ can become \/. – Jonathan Frech – 2018-02-09T20:43:05.717

7

Haskell, 90 88 87 82 bytes

1 6 bytes saved thanks to Lynn

a#b=[1..a]>>b
x!y|i<-(x-1)#"  "=x#"/\\":(y-1)#['\\':i++"/",'/':i++"\\"]++[x#"\\/"]

Try it online!

Still feels really long, I'll see what I can do.

Post Rock Garf Hunter

Posted 2017-08-10T04:16:21.780

Reputation: 55 382

Defining a#b=[a..b] and replacing all occurences saves one byte: a#b=[a..b];x!y|i<-2#x>>" "=(1#x>>"/\\"):(2#y>>['\\':i++"/",'/':i++"\\"])++[1#x>>"\\/"] – Lynn – 2017-08-10T17:00:36.473

Oh, a#b=[1..a]>>b;x!y|i<-(x-1)#" "=x#"/\\":(y-1)#['\\':i++"/",'/':i++"\\"]++[x#"\\/"] actually saves 6~ – Lynn – 2017-08-10T17:02:52.543

@Lynn Thanks! You've really been catching my slack lately. – Post Rock Garf Hunter – 2017-08-10T17:03:12.643

@Lynn I got it to work but at the cost of another byte. – Post Rock Garf Hunter – 2017-08-10T17:06:18.343

6

05AB1E, 14 bytes

„/\|∍`S¦`).B∞∊

Try it online!

Explanation

„/\|∍`S¦`).B∞∊   Arguments: x, y
„/\              Push the string "/\"
   |             Push inputs as array: [x,y]
    ∍            Push the string extended/shortened to those lengths
     `           Flatten
      S          Push seperate chars of second string
       ¦`        Remove first char and flatten again
         )       Wrap stack to an array
          .B     Squarify
            ∞∊   Mirror on both axes

This only creates the top left corner, x characters wide and y characters tall. It then mirrors this on both axes:

x=3, y=2

/\/|
\  |
---+

kalsowerus

Posted 2017-08-10T04:16:21.780

Reputation: 1 894

4

JavaScript (ES6), 84 bytes

Takes input in currying syntax (w)(h).

w=>h=>'/\\'[R='repeat'](w)+`
${`\\${p='  '[R](w-1)}/
/${p}\\
`[R](h-1)}`+'\\/'[R](w)

Demo

let f =

w=>h=>'/\\'[R='repeat'](w)+`
${`\\${p='  '[R](w-1)}/
/${p}\\
`[R](h-1)}`+'\\/'[R](w)

function upd() { O.innerHTML = W.value+'x'+H.value+'\n\n'+f(W.value)(H.value) }
upd()
<input id=W type=range value=5 min=1 max=10 oninput="upd()">
<input id=H type=range value=5 min=1 max=10 oninput="upd()">
<pre id=O>

Arnauld

Posted 2017-08-10T04:16:21.780

Reputation: 111 334

3

Swift 3, 166 bytes

func f(a:Int,b:Int){let k=String.init(repeating:count:),n="\n";var r="\\"+k("  ",a-1)+"/";print(k("/\\",a)+n+k(r+n+String(r.characters.reversed())+n,b-1)+k("\\/",a))}

Full test suite.

The closure version is a bit longer, unfortunately (175 bytes):

var g:(Int,Int)->String={let k=String.init(repeating:count:),n="\n";var r="\\"+k("  ",$0-1)+"/";return k("/\\",$0)+n+k(r+n+String(r.characters.reversed())+n,$1-1)+k("\\/",$0)}

Test suite with the closure version.

Mr. Xcoder

Posted 2017-08-10T04:16:21.780

Reputation: 39 774

3

Retina, 77 73 bytes

\d+
$*
 1+|1(?=1* (1+))
$1¶
1
/\
.((..)*.)
/$1¶$1/
¶$

(?<=¶.+).(?=.+¶)
 

Try it online! Link includes test cases. Takes input in the format <height> <width>. Explanation:

\d+
$*

Convert the inputs to unary.

 1+|1(?=1* (1+))
$1¶

Multiply the inputs, but add a newline so that the result is a rectangle.

1
/\

Create the spiky top.

.((..)*.)
/$1¶$1/

Duplicate each spiky row, but with the spikes offset on the second row.

¶$

Delete trailing newlines.

(?<=¶.+).(?=.+¶)
 

Delete the inside of the box. (Note space on last line.)

Neil

Posted 2017-08-10T04:16:21.780

Reputation: 95 035

3

C (gcc), 170 166 158 155 108 105

-3 bytes thanks to cleblanc

x,y;f(w,h){for(y=h*=2;y--;puts(""))for(x=w*2;x--;)putchar(!x|x==w*2-1|!y|y==h-1?x&y&1|~x&~y&1?47:92:32);}

Try it online!

I think this can be golfed further with a less straightforward approach, I'll see what I can do when I find the time.

Ok I cannot find any other way to reduce the number of bytes for that code.

Explanation: a simple double-loop printing the box char by char.

When printing a border: if both x and y coordinates are either even or odd, it displays a /, otherwise, a \ is displayed

If not a border, a space character is displayed instead

scottinet

Posted 2017-08-10T04:16:21.780

Reputation: 981

1You can shave off another 3 bytes by moving the puts("") into the first for loop like this x,y;f(w,h){for(y=h*=2;y--;puts(""))for(x=w*2;x--;)putchar(!x|x==w*2-1|!y|y==h-1?x&y&1|~x&~y&1?47:92:32);} – cleblanc – 2017-08-11T15:57:03.800

@cleblanc Thanks! – scottinet – 2017-08-11T19:55:05.373

3

APL (Dyalog), 41 39 bytes

Prompts for a list of [H,W]

'\'@2@1⊢¯1⌽@1{⌽⍉⍵,'/\'⍴⍨≢⍵}⍣4⊢''⍴⍨2×⎕-1

Try it online!

⎕-1 prompt for input (mnemonic: stylized console) and subtract 1

 multiply by two

''⍴⍨ use that to reshape an empty string (pads with spaces)

 yield that (serves to separate it from 4)

{}⍣4 apply the following function four times:

≢⍵ tally (length of) the argument

'/\'⍴⍨ cyclically reshape "/\" to that length

⍵, append that to the right side of the argument

⌽⍉ transpose and mirror (i.e. turn 90°)

¯1⌽1 cyclically rotate the 1st row one step to the right

 yield that (serves to separate it from 1)

'\'@2@1 put a backslash at the 2nd position of the 1st major item.

Adám

Posted 2017-08-10T04:16:21.780

Reputation: 37 779

3

Excel, 95 bytes

=REPT("/\",A1)&"
"&REPT("\"&REPT(" ",2*A1-2)&"/
/"&REPT(" ",2*A1-2)&"\
",B1-1)&REPT("\/",A1)

Wernisch

Posted 2017-08-10T04:16:21.780

Reputation: 2 534

3

///, 172 117 bytes

So, because the output consists of ///s and whitespaces, there should be submissions in those 2 languages.

Put the input after the code in W,H as unary number (unary for /// is allowed, thanks to Challenger5 for suggestion) (use * to represent digit, separate with ,) format.

/W/VV//V/\\\///`/\\\\\\\\\\\\\V/,/W>+  V`/`\>+W  !V!``WV>+WV-  V`\
`\W+  V`/
`/W-!V`\
W``\\V`\V>!//!*/+%-%!//*/  //%/

Try it online! (with input W=4, H=3)

user202729

Posted 2017-08-10T04:16:21.780

Reputation: 14 620

You can skip the parsing by taking input in Unary.

– Esolanging Fruit – 2017-09-19T02:08:51.060

Also, I should mention that this is very impressive! Good job! – Esolanging Fruit – 2017-09-19T02:11:26.350

2

Python 3, 87 82 bytes

Edit: Saved 5 bytes thanks to @officialaimm, @Mr.Xcoder and @tsh

def f(a,b,n="\n"):r="\\"+"  "*~-a+"/";print("/\\"*a+n+(r+n+r[::-1]+n)*~-b+"\\/"*a)

Try it online!

Halvard Hummel

Posted 2017-08-10T04:16:21.780

Reputation: 3 131

81 bytes in python 2 after some improvements – officialaimm – 2017-08-10T05:11:09.267

If you want to keep it in Python 3, *(b-1) can be *~-b, for -2 bytes. – Mr. Xcoder – 2017-08-10T05:50:10.040

2@officialaimm Why " "*2*~-a? Just "__"*~-a. – tsh – 2017-08-10T05:52:04.753

@tsh Yes, you are right... Haha didn't realize that... – officialaimm – 2017-08-10T05:59:35.230

@officialaimm will keep it Python 3, did however save some bytes due to you, Mr.Xcoder and tsh – Halvard Hummel – 2017-08-10T06:25:57.433

2

SOGL V0.12, 22 21 13 bytes

/\”m;HΙ»mč+╬¡

Try it Here! (expects both inputs on stack so .. (and " because a string hasn't been explicitly started) - take number input twice is added for ease-of-use)

Explanation:

/\”            push "/\"
   m           mold to the 1st inputs length
    ;          get the other input ontop of stack
     H         decrease it
      Ι        push the last string - "/\"
       »       rotate it right - convert to "\/"
        m      mold "\/" to the length of 2nd input - 1
         č     chop into characters
          +    prepend the 1st molded string to the character array of the 2nd
           έ  quad-palindromize

dzaima

Posted 2017-08-10T04:16:21.780

Reputation: 19 048

ockquote>

:D it isn't beating Charcoal here

– ASCII-only – 2017-08-10T09:54:00.687

@ASCII-only because charcoal has a built-in for this :p (and SOGLs really made for complicated & long challenges anyway) – dzaima – 2017-08-10T10:02:58.390

2

J, 48 bytes

' '&((<,~<<0 _1)})@(+:@[$(1&|.,:])@('\/'$~+:)@])

ungolfed

' '&((< ,~ <<0 _1)}) @ (+:@[ $ (1&|. ,: ])@('\/' $~ +:)@])

explanation

                       (+:@[ $ (1&|. ,: ])@('\/' $~ +:)@])    creates box, but interior filled with slashes
                                           ('\/' $~ +:)@]       take right arg, W, doubles it, then fills that
                                          @                       many characters with '\/' repeating
                               (1&|. ,: ])                      stacks (,:) the above on top of itself rotated 
                                                                  by one char, producing top and bottom spikes
                              $                                 reshape to..
                       (+:@[                                    double the length of the left arg, height
                                                                  this creates the sides, as well as a filled interior
                     @                                    
' '&((< ,~ <<0 _1)})                                          removes slashes from interior by using the complement               
                                                                form of amend }.  ie, replace everything but the first
                                                                and last row and first and last col with a space

Try it online!

Jonah

Posted 2017-08-10T04:16:21.780

Reputation: 8 729

133 bytes ' '(<,~<<0 _1)}'\/'{~=/&(2|i.)&+:. Amend is great here. – miles – 2017-08-10T15:28:15.620

ooooh, very nice improvement – Jonah – 2017-08-10T15:34:04.030

130 bytes '/\ '{~2(<,~<<0 _1)}2|+/&i.&+: with some refactoring – miles – 2017-08-12T20:37:02.263

2

05AB1E, 19 bytes

4FNÈi¹}·„\/NÉiR}N·Λ

Try it online!

Takes arguments reversed.

Erik the Outgolfer

Posted 2017-08-10T04:16:21.780

Reputation: 38 134

Hmm, I smell... Canvas Mode? – Mr. Xcoder – 2017-08-10T10:09:50.343

2

Haskell, 84 79 bytes

w%h=[[last$"/\\"!!mod(x+y)2:[' '|x>1,y>1,x<2*w,y<2*h]|x<-[1..2*w]]|y<-[1..2*h]]

Try it online! Example usage: 3%6 yields a list of lines. Use mapM putStrLn $ 3%6 to pretty-print the box.

Laikoni

Posted 2017-08-10T04:16:21.780

Reputation: 23 676

I got my answer down below yours with the help of Lynn, but I'd love to see you beat it again. – Post Rock Garf Hunter – 2017-08-10T17:09:48.343

1@WheatWizard There you go ;) – Laikoni – 2017-08-10T17:31:09.057

2

Java 8, 141 bytes

A curried lambda from width to height to output.

w->h->{String f="/",b="\\",t=f,o=b,p="";char i=1;for(;i++<w;t+=b+f,o+=f+b)p+="  ";t+=b;o+=f;for(i=10;--h>0;)t+=i+b+p+f+i+f+p+b;return t+i+o;}

Try It Online (no, return t+i+o; was not intentional)

Ungolfed lambda

w ->
    h -> {
        String
            f = "/",
            b = "\\",
            t = f,
            o = b,
            p = ""
        ;
        char i = 1;
        for (; i++ < w; t += b + f, o += f + b)
            p += "  ";
        t += b;
        o += f;
        for (i = 10; --h > 0; )
            t += i + b + p + f + i + f + p + b;
        return t + i + o;
    }

This solution is atypically picky about input size since a char is used to count up to the width input. Fortunately, the algorithm is bad enough that at those sizes program completion is probably already an issue. I chose to use char for the loop index so I could reuse it later as a cheap alias for '\n'.

Jakob

Posted 2017-08-10T04:16:21.780

Reputation: 2 428

1

Mathematica, 87 bytes

Table[Which[1<i<2#2&&1<j<2#," ",OddQ[i+j],"\\",1>0,"/"],{i,2#2},{j,2#}]~Riffle~"
"<>""&

Try it in Mathics (it prints extra spaces at the start of most lines for some reason), or at the Wolfram sandbox! Takes two integers as input.

It's a fairly naïve solution, but all of the clever things I tried had more bytes. Something that nearly works is

ArrayPad[Array[" "&,2#-2],1,{{"/",s="\\"},{s,"/"}}]~Riffle~"\n"<>""&

except it fails if either dimension is 1 (input is a list containing the dimensions).

Not a tree

Posted 2017-08-10T04:16:21.780

Reputation: 3 106

1

Pyth, 40 39 38 bytes

+++*Q"/\\"b*tE+++K++\\*d*2tQ\/b_Kb*"\/

This takes the two integers separated by a newline.

Full test suite.

Mr. Xcoder

Posted 2017-08-10T04:16:21.780

Reputation: 39 774

1

Ruby, 62 61 60 bytes

->r,c{["/\\"*c]+["\\#{w="  "*~-c}/",?/+w+?\\]*~-r+["\\/"*c]}

-1 byte thanks to Arnauld

Try it online!

G B

Posted 2017-08-10T04:16:21.780

Reputation: 11 099

1

Actually, 38 bytes

"/\"*;.R;l¬' *"\/"@j;R(D(╗WD(;.(;.(Wé╜

Try it online!

Erik the Outgolfer

Posted 2017-08-10T04:16:21.780

Reputation: 38 134

1

J, 39 bytes

(' \/'{~=/&(2&|)(*>:)~0=*/&(*|.))&i.&+:

Try it online!

Takes two arguments as height on the LHS and width on the RHS.

miles

Posted 2017-08-10T04:16:21.780

Reputation: 15 654

Nice work, as usual. Interesting approach, too. – Jonah – 2017-08-10T15:18:58.690

@Jonah No, your idea is much better using amend. If combined with half of mine... – miles – 2017-08-10T15:27:16.950

1

R, 160 bytes 152 bytes

p=function(x,n){paste(rep(x,n),collapse='')}
function(w,h){f=p(' ',w*2-2)
cat(paste0(p('/\\',w),'\n',p(paste0('\\',f,'/\n/',f,'\\\n'),h-1),p('\\/',w)))}

Try it online!

Thanks BLT for shaving off 8 bytes.

Mark

Posted 2017-08-10T04:16:21.780

Reputation: 411

Do you ever use the s function? – BLT – 2017-09-19T03:17:15.203

The s function is what you call to make the spikey box – Mark – 2017-09-19T09:49:09.677

1Got it. You can get down to 152 bytes if you remove whitespace and the s= bit. Anonymous functions are allowed. – BLT – 2017-09-19T16:20:02.543

Good to know anon functions are allowed – Mark – 2017-09-19T16:50:02.270

1

VBA (Excel) , 161 Bytes

Sub a()
c=[A2]*2
r=[B2]*2
For i=1To r
For j=1To c
b=IIf(i=1 Or j=1 Or i=r Or j=c,IIf((i+j) Mod 2,"\","/")," ")
d=d & b
Next
d=d & vbCr
Next
Debug.Print d
End Sub

remoel

Posted 2017-08-10T04:16:21.780

Reputation: 511

Golfed Sub (139 Bytes): Sub b c=[2*A1] r=[2*B1] For i=1To r For j=1To c Debug.?IIf(i=1Or j=1Or i=r Or j=c,IIf((i + j)Mod 2,"\","/")," "); Next Debug.? Next End Sub – Taylor Scott – 2017-12-22T19:43:21.660

Anonymous immediate window function version of above (113 Bytes): c=[2*A1]:r=[2*B1]:For i=1To r:For j=1To c:?IIf(i=1Or j=1Or i=r Or j=c,IIf((i + j)Mod 2,"\","/")," ");:Next:?:Next – Taylor Scott – 2017-12-22T19:44:40.973

0

Perl 5, 83 + 1 (-n) = 84 bytes

say"/\\"x($q=$F[0]);print(("\\".($s=$"x(2*$q-2))."/$//$s\\$/")x--$F[1]);say"\\/"x$q

Try it online!

Xcali

Posted 2017-08-10T04:16:21.780

Reputation: 7 671

0

dc, 123 bytes

?1-sesf[/\]su[lfsh[lunlh1-dsh0<q]dsqx]dsrx[[
\]P[lf2*2-st[32Plt1-dst0<z]dszx]dsmx[/
/]Plmx92Ple1-dse0<l]slle0<l10P[\/]sulrx

It's far from the shortest, but, if one takes the last two lines and rotates them pi/2 radians clockwise to an "upright" position, it kind of looks like a totem pole.

Takes input as two space-separated integers.

Try it online!

R. Kap

Posted 2017-08-10T04:16:21.780

Reputation: 4 730

1Currently the longest answer here. I thought that was Java's job... – R. Kap – 2017-08-10T06:25:59.537

Don't worry, there's now a Java solution, and it's longer.

– Jakob – 2017-08-11T04:19:10.357

0

Mathematica, 116 bytes

(c=Column;o=Table;v=""<>o[" ",2*#-2];w=""<>o["/\\",#];c[{w,c@o[c[{"\\"<>v<>"/","/"<>v<>"\\"}],#2-1],Rotate[w,Pi]}])&

J42161217

Posted 2017-08-10T04:16:21.780

Reputation: 15 931

Rotate[w,Pi] is equivalent to w~Rotate~Pi, as is o["/\\",#] to "/\\"~o~# – Jonathan Frech – 2017-09-19T12:58:51.167

I know infix notation and I always use it when I really need 1 byte.In this case I just let it go... ;-) – J42161217 – 2017-09-19T14:11:26.753

2I did not doubt your knowledge of infix notation; I just wanted to reduce the byte count. You know, in the spirit of golfing and such. – Jonathan Frech – 2017-09-19T17:05:04.173

0

V, 18 bytes

Ài/\Ùæ$Àäkllòjjkè

Answer wouldn't require the ll if <M-h>ollow left 2 char columns alone :(

Try it online!

nmjcman101

Posted 2017-08-10T04:16:21.780

Reputation: 3 274

0

C# (.NET Core), 188 bytes

a=>b=>string.Join("\n",new int[2*b].Select((x,i)=>string.Concat(string.Concat(new int[a].Select(y=>i%2==0?"/\\":"\\/")).Select((y,j)=>i>0&i<2*b-1&j>0&j<2*a-1?" ":""+y))))

Byte count also includes:

using System.Linq;

Try it online!

I started making explanation command-by-command but it stopped making sense midway... Basic gist is to make full spiky box, and then hollow out the middle. I used Linq for the sake of using Linq, probably can be shorter using just standard iterations.

Here's explanation going middle-out (the inner-most command first):
First, create rows for the full box, and concatenate to a single string

string.Concat(new int[a].Select(y => i % 2 == 0 ? "/\\" : "\\/"))

Then get each character in a row, and if it isn't the outline of the box, replace with space, concatenate them back into one string for each row

string.Concat(PREVIOUS_STEP.Select((y, j) => i > 0 & i < 2 * b - 1 & j > 0 & j < 2 * a - 1 ? " " : "" + y))

Finally, get each row and concatenate them together with newlines (also includes generating of a collection for rows)

string.Join("\n", new int[2 * b].Select((x, i) => PREVIOUS_STEP));

Grzegorz Puławski

Posted 2017-08-10T04:16:21.780

Reputation: 781

0

Jelly, 19 bytes

JṖḊ
Ḥ+þ/ị⁾\/⁶Ǧ€Ç¦Y

Try it online!

How?

JṖḊ - Link 1, middle indexes: list
J   - range of length [1,2,3,...,length-1,length]
 Ṗ  - pop             [1,2,3,...,length-1]
  Ḋ - dequeue           [2,3,...,length-1]

Ḥ+þ/ị⁾\/⁶Ǧ€Ç¦Y - Main link: list of numbers [w,h]
Ḥ               - double (vectorises) -> [2*w,2*h]
   /            - reduce by:
  þ             -   outer product with:
 +              -     addition ->  [[1,2,...,w],[2,3,...,1+w],...,[h+1,h+2,...,h+w]]
     ⁾\/        - literal ['\','/']
    ị           - index into (vectorises) -> ["/\/\.../\","\/\/...\/",...,"\/\/...\/"]
             ¦  - sparse application:
            Ç   - ...to indexes: call the last link as a monad (the middle ones)
          ¦€    - ...of: sparse application for €ach:
         Ç      -        ...to indexes: call the last link as a monad (the middle ones)
        ⁶       -        ...of: a space character (blank out the middle entries)
              Y - join with newlines
                - as a full program: implicit print

Jonathan Allan

Posted 2017-08-10T04:16:21.780

Reputation: 67 804

0

APL (Dyalog), 30 bytes

' \/'[(⌽⌈⊖)3|((-0=⌊)*+)/↑⍳2×⎕]

Try it online!

ngn

Posted 2017-08-10T04:16:21.780

Reputation: 11 449

0

><>, 180 Bytes

0&0\
a*+>i68*-:0(?v$
/)\^0&1v?)0&~/
? 0 v:$<
/ \:<-1oo'/\'
\~$:@2*0&\
'/'1>&o1->a\ /'/'>o$:2*>1-:1)?\~$&1=?\
'\'0//?(3:o/?/'\'/     \o*48  /      \
/?)0\ &:&1=/;
\  \:~
'/'/\<oo'\'

Sasha

Posted 2017-08-10T04:16:21.780

Reputation: 431

0

Excel VBA, 89 Bytes

Anonymous VBE immediate window function that takes input as w from [A1] and h from [B1] and then outputs to the VBE immediate window.

a=[Rept("/\",A1)]:?a:s=space(2*[A1-1]):For i=1To[B1-1]:?"\"s"/":?"/"s"\":Next:?Mid(a,2)"/

Taylor Scott

Posted 2017-08-10T04:16:21.780

Reputation: 6 709