My problem is this:

Suppose you have N urns that contain iron of a different weights (floating points). I need to cut iron from urns and throw it into other urns until each urn contains equal amounts of iron. I need an algorithm that tells me how much iron to take from which urn and which urn to put it into.

Of course this problem has several solutions; and I can think of some algorithms. But I am asking you for some good algortihms - hopefully an algortimh that gives the solution(s) which requires least moves.

I hope I've been clear enough, but let me, just to be sure, give an example:

Urn 1: 10 kg.

Urn 2: 0 kg.

Urn 3: 3 kg.

Urn 4: 7 kg.

A 'good' solution to this is:

Take 5 kg. from urn 1 and put into urn 2.

Take 2 kg. from urn 4 and put into urn 3.

I don't necessarily need exhaust algorithm that gives me all solutions. That would of course be best, but actually I only need one solution as long as it is optimal (least moves).

Thank you very much in advance.

Tweet This+ 1 thisPost To Linkedin