I require some input on the below logic.
It is kind of billing system takes the input and has a value associated with it.
A = 2 , 3A = 5
B = 3
C = 1 , 4C = 3
My code , should be such that take ABCCBAACCA , output should be value which is 16.
My solution as of now, I m thinking to count every element in the string, and them mod(modulus) by 3 for A , 4 for C (as in the above case, no need in case of B) every element in order to get the result.
I’m confused what data structure I should be using in order to implement such system.
In pseudocode I believe it would be:
Count all A’s, B’s and C’s
Divide A’s by 3 and multiply by 5
Modulo A’s by 3 and multiply by 2
Multiply B’s by 3
Divide C’s by 4 and multiply by 3
Modulo C’s by 4
Sum the 5 results.
In Ruby it could like something like this:
Which produces: