I have two int variables a and b (defined by a user) and one modification operation for each - simple arithmetic operation like:
a += 2; b += 3;or
a -= 5; b = b*5 - 3a;or
a = a^3; b = b*a - 6b;etc.
We can change only one variable per step. We have limited number of steps - defined by user. After changing variable we are using its changed value.
Now I want to find sequence of operations which will give me situation when a and b are equal. And I'm interested in shortest way. So I get something like this: [modifyA, modifyA, modifyB, modifyA, modifyB; 5 steps] or [modifyA, modifyA, modifyB, modifyA, modifyB, modifyA, modifyA, modifyB; 8 steps] or [modifyA, modifyA, modifyB, ..., modifyB; 189 steps].
I can do it using recursive algorithm with passing the objects with step and way done but it force me to check every possibility. But with recursive if user will define 10000 steps and quite complicated operations is can be time consuming while the solution can be available after few steps. It's bit like getting binary tree with all possibilities and check each branch until solution will be found. Is there any smart way to check such tree not branch by branch but level by level?
Thanks in advance!


Sign In
Create Account


Back to top









