- #1
trollcast
Gold Member
- 282
- 13
Homework Statement
Given a limited set of operators, specifically increment and bitshift left (only 1 bit at a time) Calculate the number of operations required to get from a certain number to another.
Eg. 9 to 20 = 2 [(9++)LSHIFT]
Homework Equations
The Attempt at a Solution
I haven't started to code for it yet but I'm just wondering if my method is going to be far too inefficient at finding solutions.
If we start off with the lowest number and repeatedly multiply by 2 until it is larger than the higher number. Then Divide by 2 and repeatedly add 1 until you reach the higher number.
Go back to the lower number add 1 and repeat as above.
EG. 8 to 36
The only thing is for very large numbers I don't think this wouldn't be very efficient?
PS. Just to clarify the code isn't restricted to only those 2 operators.