/**
 * Distance Computation
 * This program computes Euclidean distance between two points in n-space.
 *
 * @author Chris Clifton
 *
 * @recitation w4 (Chris Clifton)
 *
 * @date January 20, 2010
 *
 */
import java.lang.Math;
import java.util.Date;
import java.util.Scanner;

public class Lec4Dist
{
  public static double EuclideanDistance(double[] a, double[] b)
    // Requires:  a.length = b.length; no null values in a or b
    // Produces:  Euclidean distance between a and b (>=0)
  {
    double distance = 0.;
    for (int i=0; i<a.length; i++) {
      distance = distance + (a[i]-b[i])*(a[i]-b[i]);
    }
    return Math.sqrt(distance);
  }
  
  public static final int DIMENSIONS = 10000000;
  public static void main(String args[])
  {
    double[] a = new double[DIMENSIONS];
    double[] b = new double[DIMENSIONS];
    
    for (int i=0; i < DIMENSIONS; i++) {
      a[i] = Math.random();
      b[i] = Math.random();
    }

    long time = new Date().getTime();
    double dist = EuclideanDistance(a,b);
    time = new Date().getTime() - time;
    System.out.println("Distance computed is " + dist);
    System.out.println("Distance computation took " + time + " milliseconds"); 
  }
}
