Weekly Challenge #5 – Packing Parcels

This is a (very) simplified version of the bin-packing problem. Feel free to explore this in more detail if you’re interested in learning how to optimise this algorithm.

Bronze

Laura is sending a parcel to her partner abroad. She wants to put in a variety of items, but can only send a maximum of 20kg. 

Write a program which asks the user to enter a the weight of each item. This should be repeated until a negative weight is entered.

Finally, output the total weight of the parcel. If the parcel is over 20kg, then an error message should be displayed.

Silver

Laura is finding this program useful, but she struggles to remember which items she was allowed to include in the parcel. Modify your program so that it now asks the user to enter the name of each item, as well as the weight. 

Once the total weight of the parcel is output, the program should also output each item in the parcel.

Gold

Modify your program so that once the total weight of the parcel has been output, each item is output along with the weight of each item. 

Platinum

If the parcel is over the weight limit, recommend to the user which items they could remove from the parcel in order to meet the weight limit. You should try to remove as few items as possible.