TheInsider
Programmer
Hi,
I have the following dilemma:
I want to compare sets of 2 or 3 numbers with each other to find the closest match. Lets say I want to compare 2 numbers for the following example. I have a multi-dimensional array X[5][2] containing the following arbitrary data:
X[0][0] = 1, X[0][1] = 2
X[1][0] = 2, X[1][1] = 4
X[2][0] = 5, X[2][1] = 8
X[3][0] = 7, X[3][1] = 9
X[4][0] = 3, X[4][1] = 1
Therefore my sets are:
(1, 2)
(2, 4)
(5, 8)
(7, 9)
(3, 1)
Now I want to find the index (pair) in the array that contains the closest match to the following arbitrary sets of numbers:
(4, 9)
(5, 6)
(9, 1)
My initial solution was to take the number pairs and turn them into numbers themselves.
For example the array sets would become:
(1, 2) -> 12
(2, 4) -> 24
(5, 8) -> 58
(7, 9) -> 79
(3, 1) -> 31
And my number sets to compare would become:
(4, 9) -> 49
(5, 6) -> 56
(9, 1) -> 91
Ok, now I would go through each number I created from the sets in the array and subtract my number from it. Keeping in mind to subtract the smaller number from the larger. The number created from the array set, that when subtracted from my number with the smallest difference, would be my closest match...right?
So:
49 best matches 58 -> 58 - 49 = 9 (smallest difference)
56 best matches 58 -> 58 - 56 = 2 (smallest difference)
91 best matches 79... wait a minute! The difference is being heavily weighted on the "9" in (9, 1). Neither of these two numbers should take precedence so (3, 1) is a better match, but my system does not pick this up! I would also like to be able to do this with sets of 3 or 4 numbers. Any mathematicians out there who can give me a better algorithm? Obviously creating numbers out of the set and subtracting them is not the way to go.
Any help is GREATLY appreciated!!!!! Thanks in advance.
Rob Marriott
rob@career-connections.net
I have the following dilemma:
I want to compare sets of 2 or 3 numbers with each other to find the closest match. Lets say I want to compare 2 numbers for the following example. I have a multi-dimensional array X[5][2] containing the following arbitrary data:
X[0][0] = 1, X[0][1] = 2
X[1][0] = 2, X[1][1] = 4
X[2][0] = 5, X[2][1] = 8
X[3][0] = 7, X[3][1] = 9
X[4][0] = 3, X[4][1] = 1
Therefore my sets are:
(1, 2)
(2, 4)
(5, 8)
(7, 9)
(3, 1)
Now I want to find the index (pair) in the array that contains the closest match to the following arbitrary sets of numbers:
(4, 9)
(5, 6)
(9, 1)
My initial solution was to take the number pairs and turn them into numbers themselves.
For example the array sets would become:
(1, 2) -> 12
(2, 4) -> 24
(5, 8) -> 58
(7, 9) -> 79
(3, 1) -> 31
And my number sets to compare would become:
(4, 9) -> 49
(5, 6) -> 56
(9, 1) -> 91
Ok, now I would go through each number I created from the sets in the array and subtract my number from it. Keeping in mind to subtract the smaller number from the larger. The number created from the array set, that when subtracted from my number with the smallest difference, would be my closest match...right?
So:
49 best matches 58 -> 58 - 49 = 9 (smallest difference)
56 best matches 58 -> 58 - 56 = 2 (smallest difference)
91 best matches 79... wait a minute! The difference is being heavily weighted on the "9" in (9, 1). Neither of these two numbers should take precedence so (3, 1) is a better match, but my system does not pick this up! I would also like to be able to do this with sets of 3 or 4 numbers. Any mathematicians out there who can give me a better algorithm? Obviously creating numbers out of the set and subtracting them is not the way to go.
Any help is GREATLY appreciated!!!!! Thanks in advance.
Rob Marriott
rob@career-connections.net