The eggs that ship
- O(1) · Trivial
- Free
- Python
- JavaScript
- operations
- division
Problem
At the farm, eggs are packed in cartons of per_box eggs, and a carton only ships if it's full. The ones that don't fill a carton stay behind. Write a function that takes how many eggs there are and how many fit in a carton, and returns how many eggs ship out, not how many cartons:
26 eggs at 12 per carton ship as 24. If not even one carton fills up, nothing ships.
Examples
26, 12 → 24
Past the halfway mark
22, 12 → 12
Full cartons
24, 12 → 24
Not one full carton
5, 12 → 0
Besides these, the challenge has hidden tests that are revealed when you submit your solution.
You start with this
Python
def packed(eggs, per_box):
passJavaScript
function packed(eggs, perBox) {
}Solve this challenge
It opens in your browser, with the editor and the tests. It is free and you do not need an account to start.