I have a large sorted set of numbers that I need to distribute into x ranges of numbers, such that each range contains an equal number of elements from the set, and the ranges end between the two closest elements.

For example, when x = 4 , with this set of numbers

[1, 1, 3, 5, 7, 10, 14, 25, 35, 50, 75, 100, 120, 150, 200, 260]

the output should be

[1, 6(midpoint of 5,7), 30(midpoint of 25,35), 110(midpoint of 100,120), 260]

Bonus for something I can easily translate into code as I'm not very mathematically inclined.

Also I'm not sure which category this would be under so please feel free to help me with tags.


1 Answer 1


I think this is more of a coding problem. However your question is ill-defined, so I've edited it.

What you want is for your input set S,with length L to define an array A of x+1 integers.

the first and last of your array are the first and last numbers in your set.

now each element of the array A[n] = S[(n/xL)-1] if L is odd and (S[(n/xL)-1] + S[(n/xL)])/2 if L is even.

  • $\begingroup$ How can I solve for n? Maybe I'm confusing n in A[n] and S[n], these are not equal correct? $\endgroup$ Feb 19, 2016 at 19:24
  • $\begingroup$ Is n the position in the array or the actual number? $\endgroup$ Feb 19, 2016 at 19:37

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .