title: Finding the local minima with a robot in python
body: <p>So I have been given this question and I have spent hours trying to solve it but I can't seem to get it right.</p>
  <p>Here's the question:</p>
  <p>In the number grid below, we will define a local minima as a square with the smallest number out of its four surrounding squares (above, below, to the left and to the right) that are not obstacles.</p>
  <p>Program the robot to find and paint a square that is a local minima.</p>
  <p>Functions: turnLeft(), turnRight(), forward(), paint(), squareNumber(), obstacleAhead().</p>
  <p>paint() will paint the square beneath the robot, squareNumber() checks the number of the square beneath the robot, and obstacleAhead() checks if there is a square in front of the robot.</p>
  <p>Also, using lists or defining new functions is not allowed.</p>
  <p>The program is tested with multiple grids so I need to make a solution that works for any grid.</p>
  <p>I am not sure how to make the robot move in a way that it checks all the squares but also doesn't get stuck. Any help would be appreciated!</p>
  <p><a href="https://i.stack.imgur.com/obWiU.png" rel="nofollow noreferrer">Picture of a grid</a></p>