minimizing distance between two sets (functions?)

Hi. I'm trying to minimize the distance between two sets by scaling one set. (I guess this can really be thought as the distance between two functions.) For example:

Set A = {2, 2, -4, 1}

Set B = {1, 1, -2, .0001}

So I want to minimize the following distances using a scale factor x:

d1 = 2 - x

d2 = 2 - x

d3 = -4 + 2x

d4 = 1 - .0001x

I'm really stumped! The answer should obviously be ~2, but I can't seem to figure out how to get there. Using the average x is way off (I introduced the .0001 to illustrate this). Can anyone help? Thx :)