#include "histogram.h"
#include <vector>
#include <iostream>
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);
    //std::cout<<bin_count<<endl;
    vector <size_t> bins(bin_count) ;
    dif=(max - min)/bin_count;
    for(int i=0; i < numbers.size(); i++)
    {
        bool found = false;
        for (size_t 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;
            }
  //                  std::cout<<bins[j]<<endl;

        }

        if (!found)
        {
            bins[bin_count - 1]++;
        }
//if (i==0) break;
    }
    /*for (size_t j=0; j < bin_count; j++){
        std::cout<<bins[j]<<endl;

    }*/
    return bins;
}