I tried for several hours to find a solution to what, in my opinion, was an easy task, but I could not.
I have a string consisting of 3 different characters ('I','R' & 'O') from 1 to 6 in length.
for example
IRRROO RRORRR IIR RIRRO
Each character represents a number I=1,R=2,O=3
I need to convert this string to one number, multiply by position and summarize the result. for example
IRRROO ---> (1*1)+(2*2)+(2*3)+(2*4)+(3*5)+(3*6) =52 IIR ---> (1*1)+(1*2)+(2*3) =9
Thanks in advance for your help.
text r recursion sum character
Panos Kal.
source share