Why should this be cheating?
The problem is however that you cannot be convinced not being trapped in a
local extreme.
A somewhat optimized solution would be
m=: /:~ 23 43 12 54 7 3 5 10 54 55 26 9 9 43 54 1 8 6 38 33
bu=: 4
({:,~ 2-/\]) (({~/:)+])/\. (/:(>./-<./)"1)(-bu)[\&.|.m
55 54 54 54
7 9 8 9
1 3 6 5
33 38 43 43
26 23 12 10
R.E. Boss
> -----Oorspronkelijk bericht-----
> Van: [email protected] [mailto:programming-
> [email protected]] Namens David Vincent-Jones
> Verzonden: zaterdag 16 april 2011 1:47
> Aan: Programming forum
> Onderwerp: Re: [Jprogramming] Weight distribution problem
>
> Not very scientific but ... If I question how one (I) would try to solve
the
> problem in the real world. My attempt would be to initially sort the items
> (largest to smallest) and then distribute forward and reverse among the
> boxes until I had only the 'least weighty' remaining. Those smaller
remaining
> items would be used to top-up the needy boxes.
>
> If the items are large in number and random this actually gets one quite
close
> .... but I suppose that is cheating!
>
> David
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm