Reputation: 1795
I have this trivial problem I can't solve.
I have a list of names with a value (let's say strenght) and a price. I want to understand which is the most convenient depending on the price, a sort of price/quality ratio.
Example
NAME STRENGTH PRICE
BOB 48 17
CHRIS 51 17
MARK 49 15
I want to sort this data on the price/quality ratio
Upvotes: 0
Views: 539
Reputation: 2783
Let's assume your value (quality) is strength that each player has. It also has its price.
If you want to find out which player is the most valuable, you shall divide strength/price
, because in result you'll get how many strength-units you can have for 1 price-unit. The more strength-units for 1 price-unit - the better player is, obviously.
Let's take a look at the data set below (sorted by STR/PRI
ratio descending):
NAME STRENGTH PRICE STR/PRI
JOHN 99 15 6,600
MARK 49 15 3,267
CHRIS 51 17 3,000
BOB 48 17 2,823
TOM 5 17 0,294
99 strength and only 15 price? Great, right? His ratio is 6,600.
Wait... 5 strength and 17 price? I wouldn't buy this one, and you? And look - his ratio is only 0,294.
Conclusion? The best player has the highest STR/PRI
ratio.
Now if we add PRI/STR
column to the table above (sorted from the best to the worst as above):
NAME STRENGTH PRICE STR/PRI PRI/STR
JOHN 99 15 6,600 0,151
MARK 49 15 3,267 0,306
CHRIS 51 17 3,000 0,333
BOB 48 17 2,823 0,354
TOM 5 17 0,294 3,400
You can easily notice that the best player (John) has the lowest PRI/STR
ratio.
Upvotes: 1
Reputation: 308763
We've clarified that you mean price/strength ratio.
Here's your original data set:
INDEX NAME STRENGTH PRICE RATIO
1 BOB 48 17 0.354167
2 CHRIS 51 17 0.333333
3 MARK 49 15 0.306122
If I sort these by RATIO in ascending order, the indexes are (3, 2, 1). I can tell what order NAME, STRENGTH, and PRICE need to be in by using those indexes.
Use any sorting algorithm you wish on the RATIO array and get the indexes back. Use these to refer to the original data in the order of ascending RATIO.
Upvotes: 0