Advertisement
Ozzypig

Part 1 - Exercise 3 Solution

May 21st, 2018
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.80 KB | None | 0 0
  1. -- Problem: Given a number of party guests, pizzas and slices per
  2. -- pizza, calculate how many slices each person should get so that
  3. -- everyone has the same number of slices. Also calculate the number
  4. -- of leftover slices.
  5. -- Solution: First, calculate the total number of slices available.
  6. -- Input
  7. guests = 5
  8. pizzas = 2
  9. slices_per_pizza = 8
  10. print("There are " .. guests .. " guests.")
  11. print("We ordered " .. pizzas .. " pizzas.")
  12. print("Each pizza has " .. slices_per_pizza .. " slices.")
  13. -- Calculation
  14. slices_total = pizzas * slices_per_pizza
  15. slices_per_guest = math.floor(slices_total / guests)
  16. leftover_slices = slices_total - slices_per_guest * guests
  17. -- Output
  18. print("Each person gets " .. slices_per_guest .. " slices of pizza.")
  19. print("There will be " .. leftover_slices .. " leftover slices.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement