This little example written in C# could be a good starting point:
List<double> list = new List<double>() {
0.00,0.12,0.35,0.78,0.93,1.12,1.45,1.54,
1.67,1.89,1.99,2.01,2.59,2.82};
int maxval = (int)list.Max();
Dictionary<int, int> dict = new Dictionary<int, int>();
for (int i = 0; i <= maxval; i++)
dict.Add(i + 1, list.Count(item => (int)item >= i && (int)item < (i + 1)));
How does it work?
list
is simply a list of the numbers you provided in your answer.
First I compute maximum integer I have in that list (maxval
) to know how long must be my final array.
Then I create a new Dictionary (key is horizontal value, step 1, and value is the number of numbers between the required range).
EDITED after user comment:
To read list from file you could try:
List<double> list = new List<double>();
string[] nums = File.ReadAllLines(your_file);
foreach (string num in nums)
list.Add(Double.Parse(num));
You should check if values are really doubles (maybe using Double.TryParse(...)
).
Finally: my function works even if numbers are not sorted in list.