An earlier task this week was to efficiently simulate steps, where the first two elements of a list are moved to the end of the list in reverse order.
The task can be solved even more efficiently in a way that does not simulate each step separately.
In a file flipfast.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.
The function should return an answer quickly even with very large parameters. The last function call in the code template tests this situation.
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 print(find_first(123456789, 1337**42)) # 111766959