# 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? – Nick Clifford May 20 '17 at 18:05
• @NickClifford yes. – user68614 May 20 '17 at 18:34
• Are trailing newlines allowed? – Shaggy May 20 '17 at 18:37
• Related – dkudriavtsev May 20 '17 at 18:47
• @Shaggy i'd assume so, it is yes by default on Meta. – programmer5000 May 20 '17 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

• I think you can replace Ò r|$. with Ò|è for some bytes.Try it online! – nmjcman101 Oct 30 '17 at 2:03 • @nmjcman101 Oh man, I completely forgot that è even existed. I had to rack my brain to remember what it does. But that's really clever! In fact, using the uppercase variant, È<char> can probably save some more bytes in a few other places too. Thanks for reminding me! :) – DJMcMayhem Oct 30 '17 at 17:32 # Charcoal, 34 26 bytes Ｎγ←×γ_↑+↑Ｎ_×γ=‖ＢＯγＦ⁻Ｎ¹Ｃ⁰±²  Try it online! Link is to verbose version of code. Takes parameters in the order width, depth, height. Explanation: Ｎγ Input the width. ←×γ_ Print a set of _s that go at the bottom of each layer. ↑+ Print one of the +s that go on the left. ↑Ｎ Input the depth and print that many left |s. _ Print the top left _. ×γ= Print the =s along the top. ‖ＢＯγ Copy the left column to the right. Ｆ Repeat: ⁻ ¹ One time fewer than: Ｎ Input of the height: Ｃ⁰±² Copy the whole cake up 2 characters.  ## Mathematica, 167 bytes c=Column;r=Row;t=Table;f=Flatten;c[c/@{r/@f[{{{"_",r@t["=",#],"_"}},t[{"|",r@t[" ",#],"|"},#3-1]},1],c/@f[{t[{r@{"|",r@t[" ",#],"|"},r@{"+",r@t["_",#],"+"}},#2]},1]}]&  # PHP>=7.1, 104 Bytes for([,$w,$h,$t]=$argv;$i<2*$h+$t;)echo str_pad($e="_|+"[$b=$i++<$t?$i>1:1+$_++%2],$w+1,"= _"[$b])."$e ";  Online Version • Not bad. Found 3 byte: for([,$w,$h,$t]=$argv;$i<2*$h+$t;)echo str_pad($e="_|+"[$b=$i++<$t?$i>1:2-($i-$t&1)],$w+1,"= _"[$b])."$e\n"; – Christoph May 23 '17 at 9:32
• And another 3 byte: $b=$i++<$t?$i>1:1+$_++%2. – Christoph May 23 '17 at 9:39 • @Christoph Nice idea Thank You – Jörg Hülsermann May 23 '17 at 10:16 # Ruby, 62 bytes ->w,h,d{l="|#{' '*w}| ";"_#{?=*w}_ "+l*~-d+(l+"+#{?_*w}+ ")*h}  Try it online! # Japt, 51 47 bytes "_{ç'=}_"+WçA=" |{ç}|" +(B=" +{ç'_}+" +(´V çA+B  Try it online! Input is taken in the order width, height, depth. # Jelly, 30 29 bytes -1 byte switching from an addition to an XOR to translate between outer and inner columns, allowing for a 5 character lookup rather than having two _ entries. ṬṚ;⁹RḤṬḤ¤Wµ^9ẋ⁵;@;µZị“_+= |”Y  Full program taking three program arguments of depth, height, width and printing the cake. Try it online! ### How? ṬṚ;⁹RḤṬḤ¤Wµ^9ẋ⁵;@;µZị“_+= |”Y - Main link: depth, height (width is a program argument) Ṭ - untruth [0,0,0,...1] such that the length is the depth Ṛ - reverse [1,0,0,...0] ¤ - nilad followed by link(s) as a nilad: ⁹ - link's right argument, height R - range [1,2,3,...,height] Ḥ - double [2,4,6,...,2*height] Ṭ - untruth [0,1,0,1,0,1,...,0,1] (length double height) Ḥ - double [0,2,0,2,0,2,...,0,2] ; - concatenate [1,0,0,...,0,0,2,0,2,0,2,...,0,2] - ...this is the form of a column of cake! W - wrap in a list µ - monadic chain separation, call that c ^9 - bitwise XOR c with 9 [8,9,9,...,9,9,11,9,11,9,11,...,9,11] ⁵ - program's 3rd argument, width ẋ - repeat the augmented c width times ;@ - concatenate with a copy of c ; - concatenate a copy of c µ - monadic chain separation call that sideways cake Z - transpose the sideways cake to put it the right way up “_+= |” - literal ['_','+','=',' ','|'] (cake decoration) ị - index into (1 based and modular, so 8,9, and 11 are, mod 5, 3, 4, and 1 yielding '=', ' ', and '_') Y - join with new lines - implicit print  # 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;s+="=",t+=" ")u+="_";s=s+"_";t="\n"+t+"|";u=t+"\n"+u+"+";for(;a-->1;)s+=t;for(;a-->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; 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-->1; ) // add the top of the cake s += t; for(; a-->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-->1;)s+=t;. But nice answer, +1 from me. – Kevin Cruijssen Oct 30 '17 at 12:43 # 05AB1E, 33 31 bytes '_'=¹×«Ć,'|¹úRĆ³G=}²F='+'_¹×«Ć,  Try it online! ## Explanation '_'=¹×«Ć,'|¹úRĆ³G=}²F='+'_¹×«Ć, Main link. Args: w h d '_ Push literal '_' '=¹× Push '=' w times «Ć, Concat, enclose and print '| Push literal '|' ¹ú Pad with w spaces in front RĆ Reverse and ecnlose ³G } d - 1 times do: = Print without consuming ²F h times do: = Print without consuming '+ Push literal '+' '_¹× Push '_' w times «Ć, Concat, enclose and print  # 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 May 23 '17 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? – stevefestl May 23 '17 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 May 23 '17 at 8:49 • @Neil It's all fixed :) – stevefestl May 23 '17 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 May 23 '17 at 9:10 # Haskell, 87 bytes f w t d=["_=| +_\n"!!j|i<-0:([2..d]>>)++([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. – Laikoni May 23 '17 at 20:01 # 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. – recursive Oct 30 '17 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. – dzaima Oct 30 '17 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! # 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)."_\n".($l='|'.$"x$w."|\n")x($F-1).("$l+".'_'x$w."+\n")x$F


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[r='repeat'](w)+a+
)=>g('_=')+(l=g('| '))[r](d-1)+(l+g('+_'))[r](h)


Here's a demo.

var F = (w,h,d,f=a=>a+a[r='repeat'](w)+a+
)=>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!