# Bake me a cake!

This is a cake:

_========_
|        |
+________+
|        |
+________+
|        |
+________+


It is 8 wide, 3 tall, and 1 deep.

You must write a program that makes a cake from 3 inputs. The first input controls how many underscores there are in the middle and =s on the top. Here's the first cake with a width of 10 instead of 8:

_==========_
|          |
+__________+
|          |
+__________+
|          |
+__________+


The second input controls how tall the cake is. Here's the second cake with a height of 4 instead of 3:

_==========_
|          |
+__________+
|          |
+__________+
|          |
+__________+
|          |
+__________+


Note the repetition of the layers.

The third input controls how deep it is. That just how many | |s to include on the top. Here's the third cake with a depth of 2 instead of 1:

_==========_
|          |
|          |
+__________+
|          |
+__________+
|          |
+__________+
|          |
+__________+


You can print trailing whitespace. Test cases:

Input: 3, 3, 3

Output:

_===_
|   |
|   |
|   |
+___+
|   |
+___+
|   |
+___+


(I hope I never get this cake)

Input: 3, 2, 1

Output:

_===_
|   |
+___+
|   |
+___+


Input: 5, 5, 5

Output:

_=====_
|     |
|     |
|     |
|     |
|     |
+_____+
|     |
+_____+
|     |
+_____+
|     |
+_____+
|     |
+_____+

• Will inputs always be positive integers? Commented May 20, 2017 at 18:05
• @NickClifford yes.
– user68614
Commented May 20, 2017 at 18:34
• Are trailing newlines allowed? Commented May 20, 2017 at 18:37
• Related Commented May 20, 2017 at 18:47
• @Shaggy i'd assume so, it is yes by default on Meta.
– user58826
Commented May 20, 2017 at 18:51

# V, 25, 20 bytes

2é_Àé=ÙÒ|èÙÒ+È_ÀäkÀÄ


Try it online!

Hexdump:

00000000: 32e9 5fc0 e93d d9d2 7ce8 d9d2 2bc8 5fc0  2._..=..|...+._.
00000010: e46b c0c4                                .k..


Thanks to @nmjmcman101 for saving three bytes, and reminding me of an old operator that saved another two bytes.

Explanation:

a, b, and c are the three arguments.

2é_                   " Insert two '_' characters
Àé=                " Insert 'a' '=' characters between them
Ù               " Duplicate this line
Ò|             " Replace this whole line with '|'s
è            " *Hollow* this line (replace all the middle characters with spaces)
Ù           " Duplicate this line
Ò+         " Replace this whole line with '+'s
È_       " *Hollow* this line again, but use '_' instead of spaces
Àäk    " Make 'b' copies of this line and the line above it
ÀÄ  " Make 'c' copies of this line

• And another 3 byte: $b=$i++<$t?$i>1:1+$_++%2. Commented May 23, 2017 at 9:39 • @Christoph Nice idea Thank You Commented May 23, 2017 at 10:16 # Ruby, 62 bytes ->w,h,d{l="|#{' '*w}| ";"_#{?=*w}_ "+l*~-d+(l+"+#{?_*w}+ ")*h}  Try it online! # Haskell, 87 bytes f w t d=["_=| +_\n"!!j|i<-0:([2..d]>>[2])++([1..t]>>[2,4]),j<-i:([1..w]>>[i+1])++[i,6]]  • Nice job leaving most non-golfing languages way behind. An infix declaration (w#t)d= ... saves a byte. Commented May 23, 2017 at 20:01 # Japt, 51 47 bytes "_{ç'=}_"+WçA=" |{ç}|" +(B=" +{ç'_}+" +(´V çA+B  Try it online! Input is taken in the order width, height, depth. # dc, 108 bytes ?sdstsw95P61sc[lwsf[lcPlf1-dsf0<a]dsax]dsbx[_]p[[124P32sclbx[|]pld1-dsd0<j]dsjx43P95sclbx[+]plt1-dst0<h]dshx  Try it online! # Röda, 65 bytes a,b,c{d=" "*a;[_${"="*a}_
,|$d| *(c-1),|$d|
+${"_"*a}+ *b]}  Try it online! # Java 7, 169164 158 bytes String f(int...a){String s="_",t="|",u="+";for(;a[0]-->0;s+="=",t+=" ")u+="_";s=s+"_";t="\n"+t+"|";u=t+"\n"+u+"+";for(;a[2]-->1;)s+=t;for(;a[1]-->0;)s+=u;return s;}  Try it online! Ungolfed: String f(int...a) // saves two bytes over int a, int b, int c { String s="_", t="|", u="+"; // set up the start of each row for(; a[0]-->0; s+="=", t+=" ") // Uses the goes-to operator to fill the row u+="_"; s += "_\n"; // adds the end of each row t += "|\n"; u = t + u + "+\n"; // and combining t into u for(; a[2]-->1; ) // add the top of the cake s += t; for(; a[1]-->0; ) // add the rest of the cake s += u; return s; }  • You can save 1 byte by putting u=t+u+"+\n" inside the for-loop: for(u=t+u+"+\n;a[2]-->1;)s+=t;. But nice answer, +1 from me. Commented Oct 30, 2017 at 12:43 # Windows Batch, 211 180 163 bytes Golfed a total of 48 bytes thanks to @Neil! @for /l %%p in (1,1,%1)do @call set w= %%w%% @echo _%w: ==%_ @for /l %%p in (2,1,%3)do @echo ^|%w%^| @for /l %%p in (1,1,%2)do @echo ^|%w%^|&echo +%w: =_%+ @set w=  • 1. Using @ on each line and after do is slightly shorter than @echo off. 2. @call set w=%%w%%_ avoids setlocal enabledelayedexpansion. 3. Use @for /l %%p in (2,1,%2). 4. IMHO you should add @set w= so that the code works more than once. – Neil Commented May 23, 2017 at 7:59 • I am confused by the last part, if I don't add @set w=, will the code not work for more then once? Commented May 23, 2017 at 8:34 • 1. Your @for /l %%p in (1,1,%1)do seems to have gone missing. 2. Your cake seems to be the wrong height, at least it doesn't seem to match the test case when I try it. 3. If you run the script twice in the same command session then the cake just gets wider and wider. – Neil Commented May 23, 2017 at 8:49 • @Neil It's all fixed :) Commented May 23, 2017 at 8:57 • Great! Just a few last things I noticed: 1. You don't need the @ after the &. 2 If you change the second loop to (2,1,%3) and the third loop to (1,1,%2) then I think you can delete the echo +%w%+ line. 3. If I've counted correctly, then I think you should fill w with spaces instead of _s, as that will result in fewer substitutions. (I would use @call set w= %%w%% as otherwise the space is hard to spot!) – Neil Commented May 23, 2017 at 9:10 # SOGL V0.12, 25 bytes e =*¼_Oe↕¼|.⌡Qe╔*¼+.H«{Q;  Try it Here! Expects the input as width, depth, then height. • Is it allowed to re-order inputs? They seem to specified in a prescribed order. Commented Oct 30, 2017 at 21:28 • @recursive Usually it's allowed and nowhere does the question force the ordering and the 2nd most voted answer reorders the inputs and probably has been seen by the OP, so I'd assume it's fine. Commented Oct 30, 2017 at 21:32 # Python 2, 124122120105 92 bytes w,t,d=input() a="\n|"+w*" "+"|" print"_"+w*"="+"_"+(d-1)*a+t*(a+"\n+"+w*"_"+"+")  -15 bytes by using STDIN instead of program arguments -13 bytes by switching to Python 2 (for input()ing integers and print statement) -12 bytes from Caird Coinheringaahing Try it online! # Python 3, 124122120 105 bytes w,t,d=[int(input())for n in(1,2,3)] a="\n|"+w*" "+"|" print("_"+w*"="+"_"+(d-1)*a+t*(a+"\n+"+w*"_"+"+")) Try it online! If a full program is not required: # Python 3, 87 84 bytes lambda w,t,d:"_"+w*"="+"_"+(d-1)*("\n|"+w*" "+"|")+t*("\n|"+w*" "+"|\n+"+w*"_"+"+") Try it online! • 80 bytes Commented Oct 30, 2017 at 21:01 • @cairdcoinheringaahing 78 bytes. Commented Oct 31, 2017 at 20:22 # Javascript (ES6), 161 157 bytes f=(w,h,d)=>{r=x=>x.repeat(w);_='_';m='+'+r(_)+'+';b='|'+r(' ')+'|';c=[_+r('=')+_];for(i=d-1;i--;) c.push(b);for(i=h;i--;) c.push(b+'\n'+m);return c.join\n} console.log(f(8,3,1)); # Python 2, 93 bytes i,j,k=input() l=["|"+" "*i+"|"] for x in["_"+"="*i+"_"]+l*(k-1)+(l+["+"+"_"*i+"+"])*j:print x  Try it online! # Perl 5, 85 + 1 (-a) = 86 bytes say"_".'='x($w=$F[0])."_\n".($l='|'.$"x$w."|\n")x($F[2]-1).("$l+".'_'x$w."+\n")x$F[1]


Try it online!

# JavaScript/ES6, 90 bytes

I just wrote a rough solution, and happened to beat the existing JS answer by a whopping 56 bytes. Then I golfed off 11 bytes.

(w,h,d,g=a=>a+a[1][r='repeat'](w)+a[0]+
)=>g('_=')+(l=g('| '))[r](d-1)+(l+g('+_'))[r](h)


Here's a demo.

var F = (w,h,d,f=a=>a+a[1][r='repeat'](w)+a[0]+
)=>f('_=')+(l=f('| '))[r](d-1)+(l+f('+_'))[r](h);

console.log(F(prompt('width') || 3, prompt('height') || 3, prompt('depth') || 3));
console.log(F.toString().length);

# Canvas, 23 bytes

|＊_⁷⇵×+×∔║│Ｐ
=×_ｅＰ⁸╷｛１⁸


Try it here!

Inputs A1, A2, A3.

• A4 - _
• A5 - (Discount 1 for ")
="|"&REPT(" ",A1)&"|
"


Final output (Discount 1 for )):

=A4&REPT("=",A1)&"_
"&REPT(A5,A3-1)&REPT(A5&"+"&REPT(A4,A1)&"+
",A2)
`