This isn't as hard as I think it is - but I'm just not thinking right at the moment.
Ok, I'm having trouble describing what I need. so I'll give you an example. Sorry if it's hard to understand.
say I have an array of numbers:
(15,5,25,10,20)
the percentage of each number can be represented in an array by dividing each element by the sum of all of them (75):
(0.2, 0.0667, 0.333, 0.133, 0.267)
now, I have a second arbitrary value (let's say 20) that needs to be multiplied by one of these percentages, and added to the original element, such that the highest numbers are added to 20 * the lowest percentage.. but the orignal array must remain in order.
if the original array and percentage array were ordered, they'd become:
(5, 10, 15, 20, 25) and (0.0667, 0.133, 0.2, 0.267, 0.333)
so in THIS order, we get:
5 + (20 * 0.333) = 11.66
10 + (20 * 0.267) = 15.34
15 + (20 * 0.2) = 19
20 + (20 * 0.133) = 22.66
25 + (20 * 0.0667) = 26.334
but it needs to be in the same order as the original array:
Such that the original array:
(15,5,25,10,20)
becomes:
(19, 11.66, 26.334, 15.34, 22.66)
The only way I can think of doing this is to sort the array manually, so that you can sort a second array at the same time containing index values. Then multiply each by the inverse percentage, then "unsort" the array again using the array of indexes that was sorted at the beginning. I'm wondering if there's an easier way though. I hate writing manual sort algorithms.
Ok, I'm having trouble describing what I need. so I'll give you an example. Sorry if it's hard to understand.
say I have an array of numbers:
(15,5,25,10,20)
the percentage of each number can be represented in an array by dividing each element by the sum of all of them (75):
(0.2, 0.0667, 0.333, 0.133, 0.267)
now, I have a second arbitrary value (let's say 20) that needs to be multiplied by one of these percentages, and added to the original element, such that the highest numbers are added to 20 * the lowest percentage.. but the orignal array must remain in order.
if the original array and percentage array were ordered, they'd become:
(5, 10, 15, 20, 25) and (0.0667, 0.133, 0.2, 0.267, 0.333)
so in THIS order, we get:
5 + (20 * 0.333) = 11.66
10 + (20 * 0.267) = 15.34
15 + (20 * 0.2) = 19
20 + (20 * 0.133) = 22.66
25 + (20 * 0.0667) = 26.334
but it needs to be in the same order as the original array:
Such that the original array:
(15,5,25,10,20)
becomes:
(19, 11.66, 26.334, 15.34, 22.66)
The only way I can think of doing this is to sort the array manually, so that you can sort a second array at the same time containing index values. Then multiply each by the inverse percentage, then "unsort" the array again using the array of indexes that was sorted at the beginning. I'm wondering if there's an easier way though. I hate writing manual sort algorithms.