23
I like pizza!
Task
Given the radius of a pizza and a list of ingredients, create the corresponding ascii pizza!
Example size 4 pizza with mozzarella cheese, olives and ham:
#####
#@@@@M#
#H@O@@@@#
#M@@@H@@#
#@OO@@@@#
#@@H@@@@#
#M@M@@@@#
#O@@@H#
#####
Input
A positive integer r
for the size of the pizza and a (possibly empty) list of ingredients (non-empty strings). The list of ingredients can be given in a series of convenient formats, including but not limited to:
- a list of ingredients, such as
["tomato", "ham", "cheese"]
; - a list of the initials, such as
["t", "h", "c"]
; - a list of left- or right-padded ingredients, such as
["tomato", "ham ", "cheese"]
or["tomato", " ham", "cheese"]
; - a string with the initials, such as
"thc"
.
Output specs
The pizza is built on a square of size 2r+1
characters, with the centre character having coordinates (0,0)
for the purposes of this explanation. All characters in the square have integer coordinates. Then,
- a position is crust
#
if its coordinatesx,y
satisfy \$r+1 > \sqrt{x^2 + y^2} \geq r\$; - a position is dough
@
if its coordinatesx,y
satisfy \$ r > \sqrt{x^2+y^2}\$.
Then, the ingredients must be put randomly on the pizza. Each ingredient will be represented by its initial and you must place r
of each ingredient randomly in the dough characters. You can assume there will be enough space in the pizza. Ingredients cannot be placed on top of eachother, so in the final pizza there must be exactly rl
non-dough symbols, in groups of r
, if the ingredients list has size l
.
For the randomness in the distributions of ingredients on top of the pizza, it suffices that for a fixed r
and ingredient list, all ingredient distributions obeying the specs have non-zero probability of occurring.
Examples
r = 1
, no ingredients
###
#@#
###
r = 2
, no ingredients
#####
#@@@#
#@@@#
#@@@#
#####
r = 5
, no ingredients
#######
##@@@@@##
##@@@@@@@##
#@@@@@@@@@#
#@@@@@@@@@#
#@@@@@@@@@#
#@@@@@@@@@#
#@@@@@@@@@#
##@@@@@@@##
##@@@@@##
#######
r = 4
, ingredients = ["bacon", "mozzarela", "tomato"]
#####
#@@b@m#
#@@@@@b@#
#@@@btb@#
#@@@@@@t#
#@@@@@@@#
#@mt@@@@#
#t@mm@#
#####
Please include one or two of your favourite pizzas in your answer :)
This is code-golf so shortest submission in bytes, wins! If you liked this challenge, consider upvoting it... And happy golfing!
3(Off topic.) Pizza Hut is serving square pizzas ... but not as small as the cases 1 and 2 in the challenge. – a'_' – 2020-02-17T08:25:31.083
@a'_' that sounds interesting! – RGS – 2020-02-17T08:30:44.487
1Are you trying to out-pizza the hut?!? – Lyxal – 2020-02-17T09:00:04.293
I like pasta - I'll wait for your tagliatelle challenge :) – Galen Ivanov – 2020-02-17T09:50:57.327
1Bonus if your program is spaghetti code – Luis Mendo – 2020-02-17T09:59:28.117
@GalenIvanov still cooking that one – RGS – 2020-02-17T10:56:15.203
8My favorite pizza is spam egg sausage and spam, 'cause that's not got much spam in it. – Arnauld – 2020-02-17T11:54:46.263
1Related – Arnauld – 2020-02-17T13:41:10.130
How flexible is the input format? An answer for example seems to take a sigle string with the initials. Is that allowed? How about a space-right-padded char matrix like this (note the right-padding in each row)?
– Luis Mendo – 2020-02-17T16:09:06.423@LuisMendo I would say that is still fairly acceptable. – RGS – 2020-02-17T17:46:28.843
@RGS Which of the two options? Or both? Perhaps edit that into the challenge text, so it's clear to everyone – Luis Mendo – 2020-02-17T22:35:35.080
@LuisMendo both; I edited the challenge, hope it is more clear now. – RGS – 2020-02-17T22:40:50.100
2@RGS Thanks. Using the initials may be an important simplification for some answers. Perhaps you should notifiy them? – Luis Mendo – 2020-02-17T22:45:17.463
@LuisMendo done as suggested! Thanks for your feedback. – RGS – 2020-02-17T22:51:43.477