Skip to content

Instantly share code, notes, and snippets.

@zacwasielewski
Last active September 28, 2020 15:51
Show Gist options
  • Save zacwasielewski/887564cca96cdc83d51ff8f048a347f4 to your computer and use it in GitHub Desktop.
Save zacwasielewski/887564cca96cdc83d51ff8f048a347f4 to your computer and use it in GitHub Desktop.
Rendezvous with cassidoo question of the week – September 28th, 2020
# 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