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

27.27% Correct | 72.73% Incorrect
Last Solution submitted on Jul 24, 2023

Problem Comments

Solution Comments

Show comments

Problem Recent Solvers11

Suggested Problems

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!