#include "histogram.h"
#include <vector>
using namespace std;
void
find_minmax(const vector<double>& numbers, double& min, double& max)
{
    min = numbers[0];
    max = numbers[0];
    for ( size_t i=0; i < numbers.size(); i++)
    {
        if (numbers[i] > max) max=numbers[i];
        if (numbers[i] < min) min=numbers[i];
    }
};

std::vector<long long unsigned int>
make_histogram(const vector<double>& numbers,size_t bin_count)
{
    float lo,hi,dif;
    double min, max;
    find_minmax(numbers, min, max);
    vector <size_t> bins(bin_count) ;
    dif=(max - min)/bin_count;
    for(int i=0; i < numbers.size(); i++)
    {
        bool found = false;
        for (int j=0; (j < bin_count-1)&&!found; j++)
        {
            lo= min + j*dif;
            hi= min + (j+1)*dif;
            if ((lo <= numbers[i]) && (numbers[i] <hi ))
            {
                bins[j]++;
                found = true;
            }
        }
        if (!found)
        {
            bins[bin_count - 1]++;
        }
    }
    return bins;
}
