Get the box index of an item that is placed in one of series of boxes that increase in size?

13 Views Asked by At

My english fails me here as I don't know how better to call it then whats in the title.

Basically the boxes have ranges like this

[1] [2-3] [4-6] [7-10] and so on with each box being 1 unit bigger then the last one.

Then I have a number, say 4. I need to find out mathematically which box its in (in this instance its in box 3). How could I do that?

Also I have no idea how to tag this.

1

There are 1 best solutions below

0
On BEST ANSWER

Assuming your last box should be $[7-10]$, the upper limits of your boxes are the triangular numbers. To find which box a number $x$ is in, compute $n=\frac 12(\sqrt {1+8x}-1)$ as shown in Wikipedia and round up