Changing the Scale of a List of Numbers

I have a set of numbers, {2,3,2,4,5,10,9,9,7,12}, and I would like to change the scale. Want the lowest value to be a 1 and the highest value a 5, and the rest should map accordingly. Assuming I want to do this linearly, it’s as simple as two mx+b=c and solving for m and b.

Here’s the simple solution:

sH is the high bounds of the new scale.
sL is the low bounds of the new scale.
vmax is the max value in your original set.
vmin is the min value in your original set.
Using these values, calculate m and b:

m = (sH – sL) / (vmax – vmin)\r\n* b = sH – vmax*m
Now using the m and b values, find the scaled values for each item in your set:

m*orignalvalue + b = scaledvalue
Using my example set of {2,3,4,5,7,9,10,12} and scaling between 1 and 5.

m = (5-1)/(12-2) = 4 / 10 = 0.4
b = 5 – 12*.4 = 5 – 4.8 = 0.2
0.4*x + 0.2 = y
Applying this to the original set, we end up with {1, 1.4, 1.8, 2.2, 3, 3.8, 4.2, 5}.

The Next Big Thing (in 2005)

I was cleaning out some older email boxes today and I ran across an email draft I never sent. It’s dated December 2005, which is almost a full year prior to the first release of the iPhone.

Scenario 1 – The Shopping Wizard: You are standing in XYZ TV Mart looking for an HDTV. You pull out your widget. It uses GPS to find out where you are. You enter what your looking for, either type of product, brand, model, etc. The widget goes out and looks for places within XX miles of your current location which currently have what your looking for instock. It also compares prices between the stores. ADDED BONUS – On demand discounts (your in XYZ and you search for Foo. ABC has FOO and is offering you a 10% off coupon, which is only valid for 30 minutes).

That was in 2005! I wish I spent more time working on my “crazy” ideas.

Update: If you are looking for such an application, I recommend check out ShopSavvy.