Last active
September 28, 2020 15:51
-
-
Save zacwasielewski/887564cca96cdc83d51ff8f048a347f4 to your computer and use it in GitHub Desktop.
Rendezvous with cassidoo question of the week – September 28th, 2020
This file contains hidden or 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. | |
# | |
# Example: | |
# | |
# $ arr = [{ name: Joe, num: 9 }, { name: Cami, num: 3 }, { name: Cassidy, num: 4 }] | |
# $ gimmePizza(arr, 8) | |
# $ 2 // 16 slices needed, pizzas can be sliced into 8 pieces, so 2 pizzas should be ordered | |
def gimmePizza(people, slices_per_pizza) | |
slices = people.map{|o| o.fetch(:num)}.sum | |
(slices.to_f / slices_per_pizza.to_f).ceil | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment