view algorithms.mm @ 44:d810aa9ca03a

times. cosmetic stuff
author Robert Tubb <rt300@eecs.qmul.ac.uk>
date Mon, 15 Dec 2014 17:33:41 +0000
parents 3af380769779
children
line wrap: on
line source
//
//  algorithms.mm
//  riftathon
//
//  Created by Robert Tubb on 26/11/2014.
//
//

#include <stdio.h>
#include "algorithms.h"
float euclideanDistance(vector<int> v1, vector<int> v2) {
    if (v1.size() != v2.size()){
        cout << "ERROR ERROR: vectors must be same length for Mr Euclid";
        return 0.;
    }
    vector<float> diff;
    
    std::transform(v1.begin(), v1.end(), v2.begin(), v1.begin(), difference<float>());
    // sqr diff
    
    std::transform(v1.begin(), v1.end(), v1.begin(),squared<float>());
    float ans = std::accumulate(v1.begin(),v1.end(),0.0);
    
    return sqrt(ans);
    
};