Given an integer n ≥ 4, output a permutation of the integers [0, n-1] with the property that no two consecutive integers are next to each other. The value of a permutation
pi is the sum of
abs(pi[i] - i) for all indices
(1, 3, 0, 2)has value
(0, 2, 4, 1, 3)has value
(0, 2, 4, 1, 3, 5)has value
(0, 2, 4, 1, 5, 3, 6)has value
Score of your answer
The score of your answer is the sum of the values of your permutations for
n = 4 .. 14 plus the number of bytes your code takes. The lower the score, the better. Your code must give valid output for all those values of
You must be able to run your submission to completion on your machine.
In case of ties, time of last edit that resulted in the relevant score will be the decider.
Isn't this the same question as this one?
Answers to the linked question will not be competitive for this question as they make no effort to optimize the value of a permutation. For example for
n=10, the permutation
[1, 3, 5, 7, 9, 0, 2, 4, 6, 8] given by most of the answers there gives a value of
30. You can do much better than that.
For the permutation part of the question, the optimal value overall is at most
120. (Thank you to @Laikoni.) Whereas Dennis's answer to the previous question scores 222. (Thank you to @user202729.)