Quotes help make search much faster. Example: "Practice Makes Perfect"

Saturday, January 5, 2013

Math Problems: Meeting Minimizing Distance



Six men are located along the x-axis at points (0,0), (17,0), (40,0), (85,0), (173,0), (440,0). If the men were to have a party at some point along the x-axis, what is the minimum total distance they must walk in order to meet?

Answer: 641

Running the script below shows that if all children decide to meet at point (85,0), then the total distance is minimized.

console.log("*************************************");

var c1 = 0;
var c2 = 17;
var c3 = 40;
var c4 = 85;
var c5 = 173;
var c6 = 440;
var sum = c1+c2+c3+c4+c5+c6;

var average = sum/6;

console.log("sum: "+sum+" ave:"+average);

totalDistance = function(point){
var c = [0,17,40,85,173,440];
var total = 0;
for(var i=0; i<6; i++){
var dist = Math.abs(point-c[i]);
total+=dist
}
return total;
}

console.log(totalDistance(125.83));
console.log(totalDistance(220));
console.log(totalDistance(0));
console.log(totalDistance(17));
console.log(totalDistance(85));
console.log(totalDistance(173));
console.log(totalDistance(440));

1 comment:

  1. Please take down this post

    -Calvin Lin
    Brilliant Mathematics Challenge Master

    ReplyDelete


This is an example of scrolling text using Javascript.

Popular Posts