[TAG] Max-spread algorithm
Neil Youngman
ny at youngman.org.uk
Thu Jul 5 18:26:53 MSD 2007
On or around Thursday 05 July 2007 15:17, Ben Okopnik reorganised a bunch of
electrons to form the message:
> On Thu, Jul 05, 2007 at 08:28:19AM +0100, Neil Youngman wrote:
> > I would try something like
> >
> > assert( pork_cubes > 1 );
> > gaps = pork_cubes - 1;
> > fill = tomatoes/gaps;
> > toms_used = 0;
> > for( g = 0; g < gaps; ++g )
> > {
> > toms_in_gap[g] = ((g+1) *fill) - toms_used;
> > toms_used += toms_in_gap[g];
> > }
> >
> > I think this still biases a little towards one end, but it shouldn't be
> > too hard to add a little tweak that fixes that.
>
> It's a nice approach - it creates a list of gaps and details how many
> tomatoes should be inserted into each gap. However, it still has a
> problem - both the tomatoes and the pork chunks are integers (cutting a
> tomato to 0.666666666666667 of its original size is a little difficult -
> and recombining the remainder with the next tomato down the line is even
> more so. :) Besides, I'm struggling a bit to see how I'd convert that to
> an actual interleaved array (it may just be because I'm a bit slow on
> the uptake this morning...)
Yeah. I didn't really make the mixing of integers and floating point numbers
clear enough. Variables toms_in_gap and toms_used were always meant to be
integers :-) Would something like
toms_in_gap[g] = round(((g+1) *fill) - toms_used);
fix it?
Neil
More information about the TAG
mailing list