Recipe 66Reading Test Cases from a File

Task

You’re working in a company that develops an automated storehouse.

Your job is to calculate how many boxes are needed to pack a specific cart full of items.

Bin Packing

images/aside-icons/info.png

In the general form, this problem is known as the “Bin packing problem’’ and is proven to be NP-hard. We won’t go down the rabbit hole of what NP-hard is—if you’re curious, you can start at Wikipedia.[39] I hope to see you back soon.

After some discussions, you start by writing a simple greedy algorithm that considers only the weight of the items:

 // Item is an package item.
 type​ Item ​struct​ {
  Name ...

Get Effective Go Recipes now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.