Your task is to order the numbers 1 \dots n so that the sum of each pair of adjacent values is different from all other pairs. Any satisfying solution is acceptable.
You may assume that n is in the range 1 \dots 100
In a file permutation
, implement a function create
that returns a list where all the adjacent pair sums are different.
def create(n): # TODO if __name__ == "__main__": print(create(6)) # [3, 1, 6, 2, 4, 5] print(create(10)) # [7, 10, 3, 1, 5, 4, 8, 6, 9, 2] print(create(15)) # [9, 4, 6, 14, 15, 13, 12, 11, 5, 2, 3, 8, 1, 7, 10]
Explanation: In the code template example [3,1,6,2,4,5], the adjacent pair sums are 4, 7, 8, 6 and 9. Since the sums are all different, the solution is correct. On the other hand, [1,5,2,6,4,3] would be an incorrect solution, because 5+2=7 and 4+3=7.