Having

- a minimum
- a maximum
- number of ranges
- a value between minimum and maximum

I’m trying to come up with a method, or two, which would calculate which range the provided value belongs to.

For min=1, max = 10, number of ranges=5 the ranges would be [1,2],[3,4],[5,6],[7,8],[9-10]

The other method would behave like shown below:

- method(1)->[1-2]
- method(2)->[1-2]
- method(3)->[3-4]
- method(4)->[3-4]
- method(5)->[5-6]
- method(6)->[5-6]
- method(7)->[7-8]
- method(8)->[7-8]
- method(9)->[9-10]
- method(10)->[9-10]

This would be used for generating a legend for a map where the size of the marker depends on the range a value belongs to.

I wonder if there is a nice algorithmic solution for this.

The numbers I work with are integers.

Edit:

Another example:

For min=1, max = 3, number of ranges=2 the ranges would be

a) [1-2],[3-3]

or

b) [1-1],[2-3]

The other method would behave like shown below:

a)

- method(1)->[1-2]
- method(2)->[1-2]
- method(3)->[3-3]

or b)

- method(1)->[1-1]
- method(2)->[2-3]
- method(3)->[2-3]

I don’t have a preference for a) or b).