Thursday, September 13, 2007

beautiful solutions

working as a developer can at times be very frustrating, as things usually don't tend to happen linearly. problems tend to appear and disappear without prior notice, and the 80/20 rule (or the pareto principle) seems to apply very much. but beyond this, there are intellectually challenging problems which are at first frustrating but in the end turn into beautiful solutions. there have been two times that I have been very impressed by how we have solved our problems.

the most recent one turned out to be quite similar to the knapsack problem, but not as advanced. here's the scenario:
imagine you have a certain set of products (at least 3, could be more), and each product has their own amount. you're going to insert these into a parcel with a certain size (that you don't know ahead of time). at least one of the products you can just insert into the first parcel without adding any to the total amount in it (there could be more). you want the products to be evenly distributed in all the parcels, so that in case one parcel gets lost, you still want some amount of all the products to be delivered. and also, the last parcel has to have a minimum of 5 products in it, so that if you end up with less than that, you'll have to take a few from the second to last parcel to fill the last one up. naturally you want to fill all your other parcels, so that you have the minimum amount of parcels needed.

now, how would you solve this ... beautifully? :)

No comments:

Post a Comment