Created
September 28, 2020 11:55
-
-
Save les-peters/bf174f9a3a48d7a3553404d223662de5 to your computer and use it in GitHub Desktop.
Pizza Planet!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import math | |
def gimmePizza(consumers, slices_per_pizza): | |
slices_to_consume = 0 | |
for consumer in consumers: | |
slices_to_consume += consumer['num'] | |
pizzas = math.ceil((slices_to_consume / slices_per_pizza)) | |
return pizzas | |
def pickyEaters(consumers, slices_per_pizza): | |
slices_to_consume = {} | |
pizzas_to_buy = {} | |
for consumer in consumers: | |
type = consumer['type'] | |
if type not in slices_to_consume.keys(): | |
slices_to_consume[type] = consumer['num'] | |
else: | |
slices_to_consume[type] += consumer['num'] | |
for type in slices_to_consume.keys(): | |
pizzas_to_buy[type] = math.ceil((slices_to_consume[type] / slices_per_pizza)) | |
return pizzas_to_buy | |
arr = [{ 'name': 'Joe', 'num': 9 }, { 'name': 'Cami', 'num': 3 }, { 'name': 'Cassidy', 'num': 4 }] | |
print(gimmePizza(arr, 8)) | |
arr = [ | |
{ 'name': 'Joe', 'num': 9, 'type': 'pepperoni' }, | |
{ 'name': 'Cami', 'num': 3, 'type': 'hawaiian' }, | |
{ 'name': 'Cassidy', 'num': 4, 'type': 'pepperoni' } | |
] | |
print(pickyEaters(arr, 8)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment