% random_walk.m
%
%  A person is standing at the middle of 10 foot long board.
%  The person takes 20 steps, each step randomly chosen to be of size
%  -1 (to the left), 0 (don't move) or +1 (to the right).
%
%  Does the person fall off the board after twenty steps?
%
falls_off = false;
position = 0;

for step = 1 : 20

  step_size = randi ( [ -1, +1 ] );
  position = position + step_size;

  if ( position < -5 || +5 < position )
    falls_off = true;
    break;
  end 

end

if ( falls_off )
  fprintf ( '  Fell off on step %d\n', step );
else
  fprintf ( '  Safe at position %d\n', position );
end
