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
Solution Comments
Show commentsProblem Recent Solvers26
Suggested Problems
-
Find the longest sequence of 1's in a binary sequence.
6816 Solvers
-
521 Solvers
-
Get the elements of diagonal and antidiagonal for any m-by-n matrix
520 Solvers
-
Create a vector whose elements depend on the previous element
802 Solvers
-
longest common substring : Skipped character version
55 Solvers
More from this Author174
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
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).