Solution for the code eval grid walk problem