[Gllug] OT: algorithm needed
Ben Whyte
ben at whyte-systems.co.uk
Sun Aug 10 20:46:41 UTC 2008
salsaman at xs4all.nl wrote:
> Hi,
> here is one for the maths lovers.
>
> I am trying to devise an algorithm to read in blocks from disk. There is a
> total read size, and a max block size.
>
> On each read I read in max_block_size or less bytes, until the total is
> reached.
>
> However, I want the last read to be as close to max_block_size as possible.
>
> E.g. if total==100, max==45, I could read:
>
> 45, 45, 10.
>
> However it would be preferable to read:
>
> 40, 40, 20, or better yet:
>
> 35, 35, 30
>
>
> Also, I want to do this without pre-calculating, i.e the next block size
> must be calculated from total and max.
>
> Any ideas ? Is there a simple algorithm to do this ?
>
>
> Gabriel.
> http://lives.sourceforge.net
>
>
Cant you do this by taking the total and dividing it by the max which
gives you the number of times that the max goes into the total, then
divide the total by this number which will give you equal number of blocks.
Wouldnt that give you what you want ?
Ben
--
Gllug mailing list - Gllug at gllug.org.uk
http://lists.gllug.org.uk/mailman/listinfo/gllug
More information about the GLLUG
mailing list