Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

(Number Grid - Optional Bonus) I like games. One of my favorite games is \"numbe

ID: 3854319 • Letter: #

Question

(Number Grid - Optional Bonus) I like games. One of my favorite games is "number grid", and the mechanics are as follows: We are given an m times n grid of positive integers A (except for one cell, mentioned below). We start at cell (1, 1). At any turn, we choose to move right, down, up, or left: however, we must move (in a direction) exactly by the number in the currently viewed cell. If the number on the square is too large for any direction to move, we can choose to wrap around the grid in modulo fashion. For example, if m = n = 5, we are at cell (2, 3) and it has value 6, then moving down will put us at cell ((2 + 6) mod 5, 3) = (3, 3). The other three cardinal directions are handled similarly. Our goal is to reach the only special cell, at a given location A[i][j] where (i, j) notequalto (1, 1), in the fewest moves possible. Design an efficient algorithm that, given such a grid A, returns the smallest number of moves to reach the special cell: if this task is not possible, the algorithm then correctly reports 0.

Explanation / Answer

Algrithm for smallest number of moves to reach the special cells:

Hence, this is the algorithm for finding a grid A that returns the smallest number of moves to reach the special cell.

Please rate the answer if it helped.....Thankyou

Hope it helps.....