# Thread: Practical math problem...sort of a puzzle

1. ## Practical math problem...sort of a puzzle

I am writing a program to delete old files on a computer. There will be a number of existing files and then a number of files to keep. You can also specify a "density" which determine which files are kept. The density is between 1 and 10. 1 indicates that older files will be kept more and 10 indicates that newer files will be kept. 5 indicates an equal number of older/newer files will be kept.

The problem is, how do you represent this mathematically? For example, if you have 10 files and want to keep 5 and the density is 5, then you just keep every other file. If the density is 2 and there are 10 files and you want to keep 4 though, how can that be represented mathematically?

I am assuming exponents/logarithms need to be used, but have yet to come up with a formula. Basically, taking the example above, when plugging in 1,2,3,4 (kept files= 1 to N, N=num kept), it returns the files you should keep (which would be something like 1,3,4,6 if density=2). Note that the files kept is loose....just as long as it skews toward the density. Nothing exact is needed. I expect that X would be the iteration for number to keep (like 1 to 4) and Y would be the density factor. The result would be the file # to keep, with files being numbered sequentially from 1 to N with 1 being the oldest.