Python Question:
Johnny has some difficulty memorizing the small prime numbers.So, his computer science teacher has asked him to play with thefollowing puzzle game frequently. The puzzle is a 3x3 boardconsisting of numbers from 1 to 9. The objective of the puzzle isto swap the tiles until the following final state is reached:
1 2 3
4 5 6
7 8 9
At each step, Johnny may swap two adjacent tiles if their sum isa prime number. Two tiles are considered adjacent if they have acommon edge. Help Johnny to figure out whether the given 3-by-3board can reach the goal state or not. Define a function`solve_puzzle` that takes an 3-by-3 numpy array (i.e., an ndarray)as its only argument and returns Python Boolean that is True if andonly if the given 3-by-3 board can reach the goal state. Hint: Youcan start from the goal state, walk through all the possible statesand save them into a global variable. You function just need tojudge if the given state is inside the possible states or not.