This is for a personal project.
I have a start number, and an interval. The start number will stay the same while sorting, but I can't know what it is ahead of time. For start number = 50,000, and interval = 4050, my bins look like: 0) 50,000, 1) 54,050, 2) 58,100, ....
I have a list of number that I want to fit into the right bins. The right bin is the bin closest to the value of the number I'm fitting at the time. If a number is lower than the start number, I throw it away. If my list is [50,000, 55,000, 60,000], then the numbers would go into bins 0, 1, and 2, respectively. I don't want to round up or down as a rule - I want to go in whichever direction gets the number to the bin that's closest to its value.
I've tried taking numbers from the list, rounding the result of that number divided by the step size (in/4050), and subtracting from that round(first_number/step_size). That works ok, but it doesn't seem to work in all cases (it's not always accurate).
How can I sort these numbers into these bins?
Let $S$ be your "Start number" and $I$ be your "interval". You can create actual bins by saying
$B_0 = [S, S+I/2), B_1 = [S+I - I/2,S+I + I/2), , B_2 = [S+2I - I/2,S+2I + I/2)...$
where
$B_n = [S+nI - I/2, S+nI + I/2]$.
Now you can say that a number $t$ should be binned into bin $n$ when it is inside the interval $B_n$.