Skip to the content

The boxes you need

Problem

You're packing books into boxes, and each box holds per_box books. Write a function that takes how many books there are and how many fit in a box, and returns how many boxes you need to pack them all.

The last box can go half empty and you still have to buy it:

9 books at 4 per box need 3 boxes.

If there are no books, you need no boxes.

Examples

  • 9, 4 → 3

  • An exact fit

    12, 4 → 3

  • Fewer books than the box holds

    3, 5 → 1

Besides these, the challenge has hidden tests that are revealed when you submit your solution.

You start with this

Python

def boxes(books, per_box):
    pass

JavaScript

function boxes(books, 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.

More O(1) challenges

See all challenges →