You are required to implement the function minimum_coin_permutations(n, p, s) which computes the minimum number of coin swaps needed to transform the permutation p into the target permutation s. The function should also return the specific swap operations that achieve this transformation.
Functionality
Create a mapping from the elements of the target permutation s to their respective indices.
Transform the input permutation p into a list of indices that correspond to the positions of its elements in s.
Calculate the minimum number of swaps required to sort this list of indices into their proper order.
Keep track of the specific swap operations (1-based indices) performed during the process.
Return the total number of swaps and the list of operations as a tuple.
Input/Output Requirements
Input:
n (int): The size of the permutations p and s.
p (list of int): A permutation of integers from 1 to n that needs to be transformed.
s (list of int): The target permutation of integers from 1 to n.
Output:
Returns a tuple consisting of:
An integer representing the minimum number of swaps needed.
A list of tuples, where each tuple contains two integers representing the indices (1-based) of the elements that were swapped.
Example
python
# Example input
n = 5
p = [2, 3, 1, 5, 4]
s = [1, 2, 3, 4, 5]
# Example output
# (2, [(1, 3), (4, 5)]) # means 2 swaps were performed: 1 with 3 and 4 with 5.
Implementation
Your implementation must be written in a file named /app/solution.py. Ensure the code is well-documented and includes relevant comments for clarity.