Initially the list contains the integers in order. In each step, the first two elements of the list are moved to the end of the list in reverse order. What is the first element of the list when all steps have been completed?
For example, starting with the list and performing three steps, the list changes as follows:
After the steps, the first element of the list is .
In a file fliptwo.py
, implement the function find_first
that takes the list size and the number of steps as parameters. The function should return the first element of the list after the steps.
Implement the function so that each step can be performed quickly. The function should return an answer immediately even with the last test case in the code template.
def find_first(size, steps): # TODO if __name__ == "__main__": print(find_first(4, 3)) # 4 print(find_first(12, 5)) # 11 print(find_first(2, 1000)) # 1 print(find_first(99, 555)) # 11 print(find_first(12345, 10**6)) # 12295