Answer the question
In order to leave comments, you need to log in
How to fill in the missing elements of the dictionary?
Hello, there is a certain ordered dictionary SortedDictionary, with a dimension of 360 elements, which receives data {int, float}, where int є [0; 360] (you can think that int is something like id), float is any. But, the catch is that in the n-th number of elements there is no value for float.
The task is to fill each empty element of the dictionary with the help of two neighboring elements (the float variable is equal to their arithmetic mean), provided:
1. If the unknown float is the very first in the dictionary, then it is simply assigned the value of the second element.
2. If an unknown float is in last place, then it is assigned the value of the penultimate element.
3. If several unknown elements are in a row, then the float value of the first such element is the arithmetic mean of the first known element before this row and the first known element after this row.
Here is a good example (let "?" be an unknown float):
{{1, ?}, {2, 20}, {3, 18}, {4, ?}, {5, ?}, {6, ?}, {7, 13}, ..., {359, 8}, {360, ?}}
PS The algorithm seems to be the simplest, but, apparently, I didn't get enough sleep today and I don't understand what to do here at all.
Answer the question
In order to leave comments, you need to log in
1 - I think the Unity tag is superfluous here))
2 -
3. If several unknown elements are in a row, then the float value of the first such element is the arithmetic mean of the first known element before this row and the first known element after this row.Well, here something falls out of the series .. why not build a discrete series of averages between the initial and final ones? .. but these are also thoughts out loud. if your conditions are set from the outside or you rigidly insist that this is the only way , then the master
float[360]
. float?[360]
( Nullable ) is a good way to distinguish a value that has not yet taken on a numerical value, without creating any other abstruse abstractions ... Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question