Can you help me to figure out how this outout emerged? A sequence of N data points as a list of com

aangenaamyj

aangenaamyj

Answered question

2022-07-12

Can you help me to figure out how this outout emerged?
A sequence of N data points as a list of comma separated integer values.
Task is generate N values representing the original values, but obfuscating their real values.
You should do this by selecting the highest and lowest value in the data set and creating N−2 data points numerically evenly spaced out between the two. Your output should be a comma separated list of N integer values ordered from low to high. Where the numbers are not integer, you should round them such that they end up integer.
Example 1:
Input: "3,2"
Output: "2,3"
Explanation: The lowest and highest values are 3 and 4 respectively, and there are no intermediate values that need to be interpreted
Example 2:
Input: "4,5,3,5"
Output: "3,4,4,5"
Explanation: The lowest and highest values are 3 and 5 and the intermediate values become 3.66 and 4.33, which when rounded to integers to make as 4 and 4.

Answer & Explanation

zlepljalz2

zlepljalz2

Beginner2022-07-13Added 22 answers

In the second example there are 4 data points, the smallest being 3 and the largest
5. Thus, we want to produce 4 equally spaced points 3,a,b,5.
The gap between 3 and 5 is 5−3=2 units long, and we want to put 2 points into it. Those 2 points create 3 gaps, which are all supposed to be the same length:
a 3 = b a = 5 b .
This means that the gap between consecutive points must be one-third of the length of the interval from 3 to 5, i.e., 5 3 3 = 2 3 .
That puts a at 3 + 2 3 3.67 and b at
3 + 2 2 3 = 3 + 4 3 4.33, both of which round to 4.
In general if m is your smallest data point, and M is your largest, you’ll be finding N−2 equally spaced points between m and M. Those points will create N−1 equal-sized gaps, so the size of each gap must be M m N 1
Shea Stuart

Shea Stuart

Beginner2022-07-14Added 4 answers

Once one knows N the length of the input, m its minimum value and M its maximum value, the output is
( x k ) 1 k N
where x k is the nearest integer to
( N k ) m + M ( k 1 ) N 1

Do you have a similar question?

Recalculate according to your conditions!

Ask your question.
Get an expert answer.

Let our experts help you. Answer in as fast as 15 minutes.

Didn't find what you were looking for?