Problem 45426. The Tortoise and the Hare - 02
Previous problem https://www.mathworks.com/matlabcentral/cody/problems/45425-the-tortoise-and-the-hare-01
Suppose in an infinitely long line, the tortoise is standing in position 0.
From that place, it can move in both +ve and -ve direction. The condition is that, in i-th jump, it can move i step forward or backward.
So one possible scenario can be -
0 [i=1] --- 1 step forward 1 [i=2] --- 2 step forward 3 [i=3] --- 3 step forward 6 [i=4] --- 4 step backward 2 [i=5] --- 5 step forward 7 [i=6] --- 6 step backward 1 [i=7] --- 7 step forward 8
If you look carefully, you'll find that -- If the tortoise moves this way, it'll always be able to reach any destination (x).
The question is what is the minimum number of moves it'll take to reach destination x.
For example --
if x=8 >> in the above example, it takes 7 steps >> but if it moves this way -- [0,-1,1,4,8] -- steps required = 4.
So 4 is the optimum way.
Solution Stats
Problem Comments
-
2 Comments
This problem is not really about DP or GA, but it is still good.
DP or GA require few test cases, or it can quickly grow beyond what is computational through current technology. For instance, 400 steps going ve or -ve, would require a tree with 2^401-1 nodes. It doesn't matter how we choose to traverse this tree, greedy or DP, it would only be fast to find a solution if there were many possible solutions (for this problem, there are just a few correct ones).
Solution Comments
Show commentsProblem Recent Solvers11
Suggested Problems
-
2313 Solvers
-
Find the peak 3n+1 sequence value
2498 Solvers
-
260 Solvers
-
374 Solvers
-
1266 Solvers
More from this Author165
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!