11
\$\begingroup\$

April 5th is National Deep DIsh Pizza Day, the theme of this challenge. Given a positive integer n (n is greater than 0), create an ASCII deep dish pizza. Actual deep dish pizza shown:

A Pizza!

As you can see, there is a layer of crust on the bottom and surrounding the rest of the pizza.

How to make the pizza

The crust is made of two layers. The first layer will be n tall and n*3 long. Length is the number of characters (including spaces) in the highest line. So given n is 1, the first layer would look like this:

\_/  1 character tall
 3 characters long

If n is two:

\    /   2 characters tall
 \__/
  6 characters long

Now for the second layer of the crust. It will go outside the first, inner crust so therefore, it will be n+2 characters tall and (n*3)+6) characters long. Given n is one:

\       /  3 characters tall
 \     /
  \___/
   9 characters long (3 underscores, 3 slashes on either side)

If n is two:

\          / 4 characters high
 \        /
  \      /
   \____/
    12 characters long

You would then match up the two highest pairs of \/ with each other for the inner and outer crust. In n is 1:

\ \   / /
 \ \_/ /
  \___/

If done correctly, it would look like a V without the tops with a one character difference between each layer. Speaking of tops, the crust will be joined together by a pair of /\, separated by a line of underscores (n*3)+2 long to complete the crust and pizza.

Examples

If n is 1:

/\_____/\
\ \   / /
 \ \_/ /
  \___/

n is 2:

/\________/\
\ \      / /
 \ \    / /
  \ \__/ /
   \____/ 

n is 3:

/\___________/\
\ \         / /
 \ \       / /
  \ \     / /
   \ \___/ /
    \_____/

Winning Criterion

This is , so the shortest code in bytes wins!

\$\endgroup\$
  • 1
    \$\begingroup\$ Something looks off in the inner crust examples. The one for n=1 seems to small, the one for n=2 looks like the inner crust from the final n=1 example, etc... \$\endgroup\$ – Adám Apr 6 '17 at 6:13
  • \$\begingroup\$ Can we use a - instead of a _? \$\endgroup\$ – Okx Apr 6 '17 at 8:13
  • \$\begingroup\$ @Okx No you may not \$\endgroup\$ – Anthony Pham Apr 6 '17 at 11:04
  • \$\begingroup\$ Happy Deep Dish Pizza Day! \$\endgroup\$ – Arjun Apr 6 '17 at 13:07

12 Answers 12

2
\$\begingroup\$

Charcoal, 35 bytes

Nθ←_←×_θ↖θ↖²M→/P×_⁺²×²θ↘θ↘¹\×_θ‖BOθ

Try it online! Link is to verbose version of code. Explanation:

Nθ

Input the size of the pizza.

←_←×_θ

Print part of the outer crust base.

↖θ↖²

Print the outer crust left side.

M→/P×_⁺²×²θ

Print part of the top crust.

↘θ↘¹\

Print the inner crust left side.

×_θ

Print part of the inner crust base.

‖BOθ

Reflect to complete the pizza.

Note that modern additions to Charcoal shrink the size down to 31 bytes:

Nθ←×_⊕θ↖θ↖²M→/P×_⊗⊕θ↘⊕θ\×_θ‖BOθ

Try it online! Link is to verbose version of code.

\$\endgroup\$
  • \$\begingroup\$ Not sure if I accidentally introduced a bug, but the filling appears not to work properly? \$\endgroup\$ – ASCII-only Feb 28 '18 at 12:16
  • \$\begingroup\$ @ASCII-only Filling? The test case at least looks right to me; what do you think isn't working? \$\endgroup\$ – Neil Feb 28 '18 at 21:40
  • \$\begingroup\$ I think it doesn't work with inputs of 4 and up? \$\endgroup\$ – ASCII-only Feb 28 '18 at 21:47
  • \$\begingroup\$ @ASCII-only Huh, how did I overlook that... \$\endgroup\$ – Neil Feb 28 '18 at 22:17
5
\$\begingroup\$

JavaScript (ES6), 136 bytes

f=
n=>"/\\"+(r=s=>s[0][0].repeat(n-1)+s)`_`+r`_`+r`___/\\
`+r` `.replace(/ /g,"$`\\ \\$`   $'$'$'/ /\n")+r` \\ \\`+r`_/ /
`+r`  \\`+r`___/`
<input type=number min=1 oninput=o.textContent=f(this.value)><pre id=o>

The whole pizza is very repetitious so the r function (designed as a tagged template literal) repeats the first character of its input n times. This handles the top and bottom two lines of the pizza. The middle is repeated by replacing a string of blanks; the $` and $' subsitutions automatically correspond to increasing and decreasing numbers of blanks thus positioning the \ \ and / / appropriately.

\$\endgroup\$
2
\$\begingroup\$

Python 2, 153 151 bytes

Try it online

n=input()
a=' '*n
b='_'*n
print'/\\__'+b*3+'/\\'
i=0
exec"print' '*i+'\ \\\\'+' '*(3*n-2*i)+'/ /';i+=1;"*n
print a+'\ \\'+b+'/ /'
print a+' \\_'+b+'_/'

-2 bytes by substituting repeated values with variables thanks to @KoishoreRoy

\$\endgroup\$
  • 1
    \$\begingroup\$ Instead of print' '*=~n+'\\'+'_'*-~n+'_/' can you not write print' '*i+' \\_'+'_'*n+'_/'? (Or n instead of i, but I was copying the previous line.) \$\endgroup\$ – Neil Apr 6 '17 at 9:08
  • \$\begingroup\$ @Neil I can't change -~n to i, because at this point i==n. But second change is good. Also I shortended -~n, thanks to your idea \$\endgroup\$ – Dead Possum Apr 6 '17 at 9:15
  • \$\begingroup\$ I wasn't simply changing -~n to i, because I was adding the space. (But you seem to have worked that out on your own anyway. Also I already noted that n and i are the same at this point.) \$\endgroup\$ – Neil Apr 6 '17 at 9:21
2
\$\begingroup\$

MATLAB, 333 bytes

(Lazy-ish attempt)

function t(n);p=@(q)fprintf(q);s=@(x)p(' ');r=@()p('/ /');l=@()p('\\ \\');f=@()p('/');b=@()p('\\');u=@(x)p('_');h=@()p('/\\');e=@()p('\n');h();arrayfun(u,1:3*n+2);h();e();for i=1:n;arrayfun(s,1:i-1);l();arrayfun(s,1:3*n-2*(i-1));r();e();end;arrayfun(s,1:n);l();arrayfun(u,1:n);r();e();arrayfun(s,1:n+1);b();arrayfun(u,1:n+2);f();e();

Formatted:

function d(n)
p=@(q)fprintf(q);
s=@(x)p(' ');
r=@()p('/ /');
l=@()p('\\ \\');
f=@()p('/');
b=@()p('\\');
u=@(x)p('_');
h=@()p('/\\');
e=@()p('\n');
h();arrayfun(u,1:3*n+2);h();e();
for i=1:n
arrayfun(s,1:i-1); l(); arrayfun(s,1:3*n-2*(i-1)); r();e();
end
arrayfun(s,1:n); l(); arrayfun(u,1:n); r();e();
arrayfun(s,1:n+1); b(); arrayfun(u,1:n+2); f();e();

Basic idea is I have function handles to print everything, and then I just pretty much brute-force it. The one for loop is for the n layers between the very top and the bottom of the inside layer. The repetition of (spaces) and _ is done using arrayfun, with array inputs. Will try to think of more interesting ways to do this if I get more time later.

\$\endgroup\$
2
\$\begingroup\$

Charcoal, 54 52 bytes

A⁺N²β↖M↓↙¹M→↘βM↑×_β↗βM←↖¹M↓↙βM↑←×_⁺β±²↖βM↘M→×_⁺×β³±⁴

Explanation:

A⁺N²β       Assign input + 2 to the variable β
↖             Move up and left one, printing a \
M↓           Move pointer down one
↙¹            Move down and left one, printing a /
M→           Move pointer right one
↘β            Move down and right β times
M↑           Move pointer up
×_β           Write underscores β times
↗β            Move up and right β times
M←           Move pointer right one
↖¹           Move up and left one
M↓           Move pointer down one
↙β           Move down and right β times
M↑           Move up one
←             Set direction to left
×_⁺β±²        Write underscores β - 2 times
↖β            Move up and left β times
M↘           Move down and right one
M→           Move right one
×_⁺×β³±⁴      Write underscores (β * 3) - 4 times

My previous answer was in Retina, a language I haven't posted an answer to before. Now, you have an answer in Charcoal, which I haven't posted an answer to before.

Try it online!

\$\endgroup\$
2
\$\begingroup\$

PHP, 209 200 137 135 bytes

finally beating JS :)

echo($f=str_pad)("/\\",1+3*$x=$n=1+$argn,_),"/\\
";for(;$n;)echo$f("\\ \\",2*$n+$x," _"[!--$n]),"/ /
",$p.=" ";echo$f("\\",2+$x,_),"/";

Takes input from STDIN; run with -nR or order a family pizza.

breakdown

// print top
echo($f=str_pad)("/\\",1+3*$x=$n=1+$argn,_),"/\\\n";
// loop N+1 times
for(;$n;)
    // print current line and left padding for next line
    echo$f("\\ \\",2*$n+$x," _"[!--$n]),"/ /\n",$p.=" ";
// print bottom
echo$f("\\",2+$x,_),"/";
\$\endgroup\$
2
\$\begingroup\$

JavaScript (ES6), 205 bytes


This is my first post!

Add a f= at the beginning and invoke like f(arg).

n=>{a=[];w=" ";u="_";t=`/\\${u.repeat(n*3+2)}/\\
`;for(i=0;i<n+1;i++){c=i==n?u:w;a.push(`${w.repeat(i)}\\ \\${c.repeat((n+1-i*2)+n+(n-1))}/ /
`)};return [t,...a,`${w.repeat(i)}\\${u.repeat(n+2)}/`].join``}

Note: All line breaks are necessary!


f=n=>{a=[];w=" ";u="_";t=`/\\${u.repeat(n*3+2)}/\\
`;for(i=0;i<n+1;i++){c=i==n?u:w;a.push(`${w.repeat(i)}\\ \\${c.repeat((n+1-i*2)+n+(n-1))}/ /
`)};return [t,...a,`${w.repeat(i)}\\${u.repeat(n+2)}/`].join``}

document.querySelector("#elem").innerHTML = f(+prompt("Enter a Number"));
<pre id="elem">


Explanation

The code first declares an Array a. It then declares w and u having the value of whitespace and underscore respectively. Then, it declares a String variable to hold the value of the crust (which can be computed by /\+(n*3+2 underscores)+/\, as mentioned in the Challenge). After that, with a for loop and a Template Literal, the middle of the pizza is created (with each layer having i whitespaces at the starting and (n+1-i*2)+n+(n-1) whitespaces between \ \ and / /, where i represents the index of for loop). At the last, the bottom most part of the pizza is created ((i whitespaces)+\+(n+2 underscores)+/). All parts are joined together and output(ted).


If for some reason the snippet does not display the ASCII art correctly, have a look here.

Happy Deep Dish Pizza Day to everyone!


\$\endgroup\$
1
\$\begingroup\$

Batch, 200 bytes

@set l=@for /l %%i in (1,1,%1)do @call 
@set t=
@set s=
%l%set s=___%%s%%
@echo /\_%s%_/\
%l%echo %%t%%\ \%%s:_= %%/ /&call set t= %%t%%&call set s=%%s:~2%%
@echo %t%\ \%s%/ /
@echo %t% \_%s%_/

t contains the left indent while s contains the inside; its _s are subsituted with spaces on the middle rows. l just exists to avoid some repetition.

\$\endgroup\$
0
\$\begingroup\$

V, 57 bytes

i\ \´ / /ÙãxX2r_>>Ù>>lxxE2r_À­ñHãyêP>GÄXã2é ñHÄÒ_R/\$h.

Try it online!

Since, (as usual) this contains lots of nasty non-ASCII characters and unprintables, here is a hexdump:

00000000: 695c 205c b420 2f20 2f1b d9e3 7858 3272  i\ \. / /...xX2r
00000010: 5f3e 3ed9 3e3e 6c78 7845 3272 5fc0 adf1  _>>.>>lxxE2r_...
00000020: 48e3 79ea 503e 47c4 58e3 32e9 20f1 48c4  H.y.P>G.X.2. .H.
00000030: d25f 522f 5c1b 2468 2e                   ._R/\.$h.

I'll post a more detailed explanation soon, but here is a high level overview:

i\ \´ / /ÙãxX2r_>>Ù>>lxxE2r_
"Create 
"\ \    / /
" \ \__/ /
"  \____/
"This can probably be compressed a lot more

À­ñHãyêP>GÄXã2é ñ
"*arg1 times*, expand the pizza slice

HÄÒ_R/\$h.
"Add the crust
\$\endgroup\$
0
\$\begingroup\$

C (clang), 211 215 bytes

i,l;f(n){l=n*3+6;char u[l];for(i=0;i<l;)u[i++]='_';u[l-1]=i=0;printf("/\\%.*s/\\\n",l-4,u);for(;i<n;i++)printf("%*s\\ \\%*.s/ /\n",i,"",n*3-(2*i),"");printf("%*.s\\ \\%.*s/ /\n%*.s\\%.*s/\n",i,"",n,u,i+1,"",n+2,u);}

Try it online!

Pretty Code:

i,l;
f(n) {
    l = n*3+6;
    char u[l];

    // Initialize u[] with a full line of underscores,
    for (i=0;i<l;)
        u[i++] = '_';

    // Make sure the string ends in a valid way
    u[l] = i = 0;

    /* Print the crust 'top'
     * l-4 dashes are needed because '/\/\'
     * %.*s notation to pad (l-4) bytes of the underscore string
     */
    printf("/\\%.*s/\\\n", l-4,u);

    /* Print n rows of just 'walls' \ \  / /
     * each row has i=0++ leading spaces,
     * and each row has n*3-(2i) center spaces
     */
    for(; i<n; i++)
        printf("%*s\\ \\%*.s/ /\n", i,"", n*3-(2*i), "");

    /* Print i spaces, '\ \', n underlines, '/ /'
     * then i+1 spaces, '\', n+2 underlines, and '/'
     */
    printf("%*.s\\ \\%.*s/ /\n%*.s\\%.*s/\n",i,"",n,u,i+1,"",n+2,u);
}

Edits:

  • removed s[l] and associated by switching from %.s notation to %.s
  • added function wrapper for compliance & try it online
\$\endgroup\$
0
\$\begingroup\$

CJam, 74 Bytes

Way too long. I'm going to try another approach.

"/\\"ri:M3*:A2+'_*1$NL{"\ \\"AS*"/ /"3$S+A((:A;N\}M*4$A'_*4$N4$S'\A2+'_*'/

Builds the string line-by line. Nothing too crazy.

\$\endgroup\$
0
\$\begingroup\$

CJam, 89 bytes

Well, this is actually longer than my other solution at the moment, but I think it's more golfable:

ri{:T)_S*a*ee_{~'\t}%TS*aTU+*'_f+@{~'/t}%W%++z}:K~2S*f{\+}T1:U+K..e>"/\\"'_T3*(*1$++a\+N*

Stack trace:

"2" ; r
2 ; i
2 {:T)_S*a*ee_{~'\t}%TS*aTU+*'_f+@{~'/t}%W%++z} ; {}
2 {:T)_S*a*ee_{~'\t}%TS*aTU+*'_f+@{~'/t}%W%++z} ; :K
2 ; ~
2 ; :T
3 ; )
3 3 ; _
3 3 " " ; S
3 "   " ; *
3 ["   "] ; a
["   " "   " "   "] *
[[0 "   "] [1 "   "] [2 "   "]] ; ee
[[0 "   "] [1 "   "] [2 "   "]] [[0 "   "] [1 "   "] [2 "   "]] ; _
[[0 "   "] [1 "   "] [2 "   "]] ["\  " " \ " "  \\"] ; {~'\t}%
[[0 "   "] [1 "   "] [2 "   "]] ["\  " " \ " "  \\"] 2 ; T
[[0 "   "] [1 "   "] [2 "   "]] ["\  " " \ " "  \\"] 2 " " ; S
[[0 "   "] [1 "   "] [2 "   "]] ["\  " " \ " "  \\"] "  " ; *
[[0 "   "] [1 "   "] [2 "   "]] ["\  " " \ " "  \\"] ["  "] ; a
[[0 "   "] [1 "   "] [2 "   "]] ["\  " " \ " "  \\"] ["  "] 2 ; T
[[0 "   "] [1 "   "] [2 "   "]] ["\  " " \ " "  \\"] ["  "] 2 0 ; U
[[0 "   "] [1 "   "] [2 "   "]] ["\  " " \ " "  \\"] ["  "] 2 ; +
[[0 "   "] [1 "   "] [2 "   "]] ["\  " " \ " "  \\"] ["  " "  "] ; *
[[0 "   "] [1 "   "] [2 "   "]] ["\  " " \ " "  \\"] ["  " "  "] '_ ; '_
[[0 "   "] [1 "   "] [2 "   "]] ["\  " " \ " "  \\"] ["  _" "  _"] ; f+
["\  " " \ " "  \\"] ["  _" "  _"] [[0 "   "] [1 "   "] [2 "   "]] ; @
["\  " " \ " "  \\"] ["  _" "  _"] ["/  " " / " "  /"] ; {~'/t}%
["\  " " \ " "  \\"] ["  _" "  _"] ["  /" " / " "/  "] ; W%
["\  " " \ " "  \\" "  _" "  _" "  /" " / " "/  "] ; ++
["\      /" " \    / " "  \__/  "] ; z
["\      /" " \    / " "  \__/  "] "  " ; 2S*
["  \      /" "   \    / " "    \__/  "] ; f{\+}
["  \      /" "   \    / " "    \__/  "] 2 ; T
["  \      /" "   \    / " "    \__/  "] 2 1 ; 1
["  \      /" "   \    / " "    \__/  "] 2 1 ; :U
["  \      /" "   \    / " "    \__/  "] 3 ; +
["  \      /" "   \    / " "    \__/  "] ["\          /" " \        / " "  \      /  " "   \____/   "] ; K
["\ \      / /" " \ \    / / " "  \ \__/ /  " "   \____/   "] ; ..e>
["\ \      / /" " \ \    / / " "  \ \__/ /  " "   \____/   "] "/\\" ; "/\\"
["\ \      / /" " \ \    / / " "  \ \__/ /  " "   \____/   "] "/\\" '_ ; '_
["\ \      / /" " \ \    / / " "  \ \__/ /  " "   \____/   "] "/\\" '_ 3 ; T
["\ \      / /" " \ \    / / " "  \ \__/ /  " "   \____/   "] "/\\" '_ 9 ; 3*
["\ \      / /" " \ \    / / " "  \ \__/ /  " "   \____/   "] "/\\" '_ 8 ; (
["\ \      / /" " \ \    / / " "  \ \__/ /  " "   \____/   "] "/\\" "________" ; *
["\ \      / /" " \ \    / / " "  \ \__/ /  " "   \____/   "] "/\\" "________" "/\\" ; 1$
["\ \      / /" " \ \    / / " "  \ \__/ /  " "   \____/   "] "/\________/\\" ; ++
["\ \      / /" " \ \    / / " "  \ \__/ /  " "   \____/   "] ["/\________/\\"] ; a
["/\________/\\" "\ \      / /" " \ \    / / " "  \ \__/ /  " "   \____/   "] ; \+
"/\________/\
\ \      / /
 \ \    / / 
  \ \__/ /  
   \____/   " ; N*
; [implicit output]
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.