2

The title is rather vague, so my apologies there.

What I'm wanting to do is this:

I have three numbers per data set. X, Y, and Z. They are always positive and Z is a power of 2. I need to interpolate between X and Y, Z times. The distance from X to Y per interpolation is the percentage of the current iteration divided by Z. The return of the interpolation is then rounded using round to nearest. I then need to count how many of each result exists per data set.

Something like this: n(i) = Round(x + (y - x) * (i / (Z-1)))

Example (only going 3 decimals out for simplicity):

X, Y, Z
3, 5, 8

Values without rounding:

3.000   3.286   3.571   3.857   4.143   4.429   4.714   5.000

Values with rounding:

3 3 4 4 4 4 5 5

End goal:

2 3's, 4 4's, 2 5's.

This, I can do just fine. What I want to do, however, is figure out there are 2 3's, 4 4's, and 2 5's (in that order) without having to actually interpolate 8 times as the example shows. In reality, the numbers are more like 291, 3472, 8192; and I need to handle thousands of these reasonably fast.

How can I do this without iterating Z times per data set?

Edit: Y is not always larger than X. In the example, if it went 5, 3, 8.. I'd have wanted to know there were 2 5's, 4 4's, and 2 3's in that order instead.

4

1 に答える 1