
Draw Ghost Legs

Ghost leg is a well-known method used to get random results. This mechanism has the effect of changing the order in the list.
This mission is almost reversed the Follow Ghost Legs. But this mission has countless answers and asymmetric in difficulty. So You should solve the Follow Ghost Legs first.
You are given a list of result for that Ghost leg as input values. The starting value is always sequentially numbered from 1. You have to return the list of legs that match them.
- The leg is a tuple of two integers, which represent the two vertical lines connected by the leg. (The leg always connects adjacent vertical line).
- The order of legs represents the level at which they are placed (first leg is the top, and last leg is the bottom).
Your answer will be confirmed by the checker.
Examples:
def checker(func: callable, result: list[int]): your_result = sorted(result) for a, b in func(result[:]): your_result[a - 1], your_result[b - 1] = your_result[b - 1], your_result[a - 1] return your_result == result assert checker(draw_ghost_legs, [3, 2, 1]) is True # [(1, 2), (2, 3), (1, 2)] etc. assert checker(draw_ghost_legs, [3, 2, 4, 1]) is True # [(2, 3), (1, 2), (2, 3), (3, 4)] etc. assert checker(draw_ghost_legs, [1, 5, 4, 2, 3]) is True # [(3, 4), (4, 5), (3, 4), (2, 3), (3, 4)] etc. assert checker(draw_ghost_legs, [2, 3, 4, 5, 6, 1]) is True # [(1, 2), (2, 3), (3, 4), (4, 5), (5, 6)] etc.
Input: A result of 'Ghost Leg' (a list of integers).
Output: A list of legs (a list of tuple of two integers).