I am trying to make an algorithm for the following task:
- I have two integers a ≤ b
- The algorithm has to transform a into b by adding 1 and multiply by 2 operations. For example, if a = 5 and b = 23 the program should output something like 23 = ((5 * 2 + 1) * 2 + 1)
- I have to use recursion
I’ve already Googled many times but all I could find is ideas on how to transform a matrix, how to do geometric transformations, how to transform string into another string and similar stuff.
Does anybody have any ideas?
This is the way to find the transformation with the minimum number of operations:
(EDIT: Added parenthesis)