Make me a pizza

17

2

Because it's Saturday (UTC) and I'm hungry, I would like a slice of pizza. I will give you an order and I would like a nice hot pizza. Up to the challenge?

The Drive-Thru

I'll place my order wherever your drive-thru is, whether it is STDIN, a function parameter, a command-line argument, but I'm not going to put it in a variable for you. (JS function expressions must be assigned to a variable.)

The order

My order will have 2 parts. The first will be a positive, non-zero integer from 3 to 6. This is the size of my pizza. For instance, a size 6 pizza with no toppings would look like:

 /=====\
/       \
|       |
|       |
\       /
 \=====/

A size 5:

 /====\
/      \
|      |
\      /
 \====/

A size 4:

 /===\
|     |
|     |
 \===/

A size 3

 /==\
|    |
 \==/

The toppings

My toppings will be a string of UPPERCASE letters. Here are the possible values:

P - Pepperoni
S - Sausage
N - piNeapple
J - Jalapenos
B - Banana peppers
C - baCon

You must fit them on the pizza somewhere. If I order a size 4 and PSPCJ, then this is a valid output:

 /===\
|PSPCJ|
|     |
 \===/

So is this:

 /===\
|P P J|
| S C |
 \===/

And this:

 /===\
|     |
|PSPCJ|
 \===/

I am not really picky about where my toppings are on the pizza, as long as they aren't on the crust or on top of each other.

The pick-up window

I will go to a lot of places to pick up my pizza, including STDOUT, a file, the return value of a function, but not a variable.

Extra stuff

  • Standard loopholes forbidden
  • This is tagged so the shortest answer in bytes wins!
  • Don't worry about invalid input (toppings > pizza space, etc.)
  • See my answer (JS ES6) below for an example (I hope you can do better)

programmer5000

Posted 2017-03-31T15:39:24.460

Reputation: 7 828

3Umm, So you can also pick your pizza up on a Drive-thru? – Matthew Roh – 2017-04-01T01:37:21.723

1Are you picky about me filling the top right and bottom right corners of the pizza box with whitespace? ;) – DLosc – 2017-04-01T04:42:31.527

1@DLosc no, any trailing whitespace at the end of any line (including a trailing newline at the end of output) is optional but not required. – programmer5000 – 2017-04-01T11:49:09.317

1C̶a̶n̶ ̶t̶h̶e̶ ̶p̶i̶z̶z̶a̶ ̶h̶a̶v̶e̶ ̶m̶o̶r̶e̶ ̶t̶h̶a̶n̶ ̶o̶n̶e̶ ̶f̶o̶r̶ ̶o̶n̶e̶ ̶o̶f̶ ̶t̶h̶e̶ ̶t̶o̶p̶p̶i̶n̶g̶s̶?̶ ̶S̶o̶ ̶i̶f̶ ̶y̶o̶u̶ ̶l̶i̶k̶e̶ ̶p̶i̶n̶e̶a̶p̶p̶l̶e̶:̶ ̶̶5̶,̶ ̶N̶N̶N̶̶ ̶i̶s̶ ̶a̶l̶s̶o̶ ̶a̶ ̶v̶a̶l̶i̶d̶ ̶i̶n̶p̶u̶t̶ ̶(̶o̶r̶ ̶s̶h̶o̶u̶l̶d̶ ̶i̶t̶ ̶b̶e̶ ̶̶5̶,̶ ̶N̶̶ ̶i̶n̶s̶t̶e̶a̶d̶)̶?̶ Also, where are the mushrooms?.. :( EDIT: Nevermind about the first question, I see your test cases has 2x P. – Kevin Cruijssen – 2017-04-05T07:53:57.673

Can I post an orderup link? xD

– FantaC – 2017-12-28T19:35:48.127

Answers

1

Pip, 87 81 75 bytes

74 bytes of code, +1 for -l flag.

e:'/.'=Xa-1.'\Y['/'\]Xa//5J'|X2-a%2^xPs.ePy.(b.sXa*a-a-2-#b<>a+1).RVys.RVe

Takes input as command-line arguments. Try it online!

Approach

e is the top row, such as /=====\. If you reverse it, it's also the bottom row.

y is the left border, such as ["/" "|" "|" "\"]. If you reverse it, it's also the right border.

We then construct the middle by taking b, the toppings, padding it with spaces to length (a+1)*(a-2) (where a is the size), and grouping it into a list of rows.

Finally, we print the top row with a leading space; concatenate the middle between y on the left and RVy on the right, and print that; and print the bottom row with a leading space.

DLosc

Posted 2017-03-31T15:39:24.460

Reputation: 21 213

Does this work with a cheese (no toppings) pizza? – programmer5000 – 2017-04-01T11:53:28.253

@programmer5000 Yes--in that case the second cmdline arg should be an empty string (if you're running it from an actual command-line, you'll have to quote it). – DLosc – 2017-04-01T21:02:45.733

5

Python 2, 202,198,190,177,162,157,146 bytes

n,t=input()
y=n+1
s=' '
l=' /'+'='*(n-1)+'\\ '+('','\n/'+s*y+'\\')[n>4]+'\n|'
print l+t[:y].center(y,s)+('','|\n|'+t[y:].center(y,s))[y%2]+l[::-1]

Try it online!

Keerthana Prabhakaran

Posted 2017-03-31T15:39:24.460

Reputation: 759

Hey, can you assign '\\', '|', and '/ to variables to golf off a few bytes? That's how I shaved a lot off my JS answer. – programmer5000 – 2017-04-01T11:52:06.587

I'm just working on that!!!! – Keerthana Prabhakaran – 2017-04-01T11:54:38.240

1Also, can you replace the first (n-1) with (--n), the n>4s withn>3, (n+1) with (n+2), and the final (n-1) with n to shave off 4 bytes? – programmer5000 – 2017-04-01T12:00:48.470

2python doesnt support -- operator ! – Keerthana Prabhakaran – 2017-04-01T12:03:04.043

136 bytes – FlipTack – 2017-12-28T16:34:00.280

2

Python 3, 224 213 195 bytes

n,t=eval(input())
k=n+1
y=print
i=0
f,s,e,b,p="/ =\\|"
t+=s*99
y(s+f+e*~-n+b)
if n>4:y(f+t[:k]+b);i+=k
y(p+t[i:i+k]+p);i+=k
if~-n%2:y(p+t[i:i+k]+p);i+=k
if n>4:y(b+t[i:i+k]+f);i+=k
y(s+b+e*~-n+f)

Try it online!

ovs

Posted 2017-03-31T15:39:24.460

Reputation: 21 408

1

JavaScript (ES6), 170 161 bytes

(n,t,a=[1,,n%2||2,,1])=>` /=\\
/___\\
|___|
\\___/
 \\=/`[r=`replace`](/.+/g,s=>s.repeat(a.pop()||n>4))[r](/=|_\b/g,`$&`.repeat(n-1))[r](/_/g,_=>t[i++]||` `,i=0)

Starts by taking a misshapen pizza of width 2 and height 5 and stretches it horizontally and adjusts it vertically as appropriate, then replaces the interior with toppings or spaces once they run out.

Neil

Posted 2017-03-31T15:39:24.460

Reputation: 95 035

0

JS (ES6), 257 255 249 248 246 244 bytes

m=s=>t=>(r="/",k="\\",p=" ",f="\n",x="|",c=f+x,q="",t=p+t,z=(s>2?p:q)+r+"=".repeat(s-1)+k+(s>4?f+r+p.repeat(++s)+k:q)+c+p.repeat(s)+x+(!s?c+p.repeat(s)+x:q)+p+(s>5?f+k+p.repeat(s)+r:q)+f+p+k+"=".repeat(s-2)+r,i=-1,z.replace(/ /g, x=>t[++i]||p))

Call it like m(4)("PS") for 1 pepperoni and 1 sausage. Probably can be golfed more.

programmer5000

Posted 2017-03-31T15:39:24.460

Reputation: 7 828

1Jeez, give some other people time to answer :P – Pavel – 2017-03-31T17:16:53.283

1@Григорий Перельман I just wanted to provide an example, I hope this doesn't win. – programmer5000 – 2017-03-31T17:18:33.220

0

Charcoal, 37 bytes

Nθ /==×=⸿/›θ⁴⸿|‖BO↓﹪θ²‖BO⊕﹪θ²J¹¦¹⪪S⊕θ

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

Nθ

Input the size of the pizza.

 /==

Start printing the top of the pizza.

×=⸿/›θ⁴

If the pizza is one of the larger sizes, add extra to the top and side.

⸿|

Print more of the side of the pizza.

‖BO↓﹪θ²

Complete the left half of the pizza by reflection with possible overlap.

‖BO⊕﹪θ²

Complete the pizza by reflection with variable overlap.

J¹¦¹⪪S⊕θ

Input the toppings and split them into pieces so they will fit inside the pizza.

Neil

Posted 2017-03-31T15:39:24.460

Reputation: 95 035