1
$\begingroup$

I'm not great with math so please bear with me.

I have two sequences of numbers: $$ 4,3,2,1\\ 1,2,3,4 $$ I aggregate them using addition: $$ 4+3+2+1 = 10\\ 1+2+3+4 = 10 $$ I aggregate them using multiplication: $$ 4*3*2*1 = 24\\ 1*2*3*4 = 24 $$ They obviously equal the same. However, I want 4,3,2,1 to have a higher value than 1,2,3,4 when I sum them. This is because I want the earlier numbers to have a greater weight compared to the later numbers. So a sequence beginning with 4 will result in a sum greater than a sequence beginning with 1. Unfortunately I cannot use index of the sequence as the weight. The sum will be done incrementally without the index.

Using addition and multiplication results in a linear sum. I guess I need to use a non-linear function to achieve what I want? If so I wouldn't know what one to use.

I hope that makes sense.

EDIT: I do not have access to all the numbers in the sequence at the same time. All I have is the current number in the sequence (the previous ones and the next ones are unknown) and the current sum so far. ie, for 4,3,2,1 when 2 arrives I want to increment my current sum (say my current sum is 7 if I were using addition)

$\endgroup$
2
$\begingroup$

Why don't you string them together using the powers of 10, e.g. map $$a_0, a_1, a_2, \ldots \to a_0 + 10a_1 + 100a_2 + 1000a_3 \ldots$$ and then your sequences map $1,2,3,4 \to 1234$ and $4,3,2,1 \to 4321$.

UPDATE

For incremental processing, imagine knowing $s_2 = 12$ as the running total and the next number in the sequence is $a_3=3$. So you compute $$s_3 = 10s_2+a_3$$ or in general, $$s_{n+1} = 10s_n + a_{n+1}$$ and you are good for the next iteration.

$\endgroup$
  • $\begingroup$ I think there is an important detail I'm missing out. I do not have access to all the numbers in the sequence at the same time. All I have is the current number in the sequence (the previous ones and the next ones are unknown) and the current sum so far. ie, for 4,3,2,1 when 2 arrives I want to increment my current sum (say my current sum is 7 if I were using addition). $\endgroup$ – sebjwallace May 28 '18 at 17:17
  • 1
    $\begingroup$ @sebjwallace please see update $\endgroup$ – gt6989b May 28 '18 at 17:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.