Last active
September 28, 2020 11:04
-
-
Save buckmaxwell/71a94a683a09fd76dd3147885289b675 to your computer and use it in GitHub Desktop.
Cassidoo problem of the week 28.09.2020
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
# Given an array of people objects (where each person has a name and a number | |
# of pizza slices they're hungry for) and a number for the number of slices | |
# that the pizza can be sliced into, return the number of pizzas you need to | |
# buy. | |
import math | |
def gimme_pizza(people, slices_per_pie): | |
if people and slices_per_pie > 0: | |
return int(math.ceil(sum([p["num"] for p in people]) / float(slices_per_pie))) | |
return 0 | |
# Tests | |
arr = [ | |
{"name": "Joe", "num": 9}, | |
{"name": "Cami", "num": 3}, | |
{"name": "Cassidy", "num": 4}, | |
] | |
assert gimme_pizza(arr, 8) == 2 | |
arr = [ | |
{"name": "Max", "num": 9}, | |
{"name": "Ben", "num": 11}, | |
{"name": "Rebecca", "num": 4}, | |
] | |
assert gimme_pizza(arr, 8) == 3 | |
arr = [ | |
{"name": "Max", "num": 9}, | |
{"name": "Ben", "num": 11}, | |
{"name": "Sam", "num": 1}, | |
{"name": "Rebecca", "num": 4}, | |
] | |
assert gimme_pizza(arr, 8) == 4 | |
assert gimme_pizza(arr, 4) == 7 | |
assert gimme_pizza(arr, 0) == 0 | |
arr = [] | |
assert gimme_pizza(arr, 1) == 0 | |
arr = [{"name": "John", "num": 8000000000}, {"name": "Jan", "num": 1}] | |
assert gimme_pizza(arr, 1000000) == 8001 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment