Generate Permutations of a large number( probably 30) with constraints
Calculating all permutations for a list of size 30 is impossible, irrespective of the implementation approach as there will be a total of 30! permutations.
It seems to me that the permutation you require can simply be achieved by sorting the the given list though by using arr.sort() and then calculating the difference between consecutive elements. Am I missing something?
I have list of numbers ( 1 to 30 ) most probably. I need to arrange the list in such a way that the absolute difference between two successive elements is not more than 2 or 3 or 4, and the sum of absolute differences of all the successive elements is minimum.
I tried generating all possible permutations of list ranging upto 10 and 11 and then sorting them according to the cost value, but for large nmbers it takes too long.
It would take ages to get list for 30 numbers.
Is there any way I could perform the constraints while generating the permutations itself ? 
Currently I'm using itertools library for python to generate permutations.
Any help is greatly apprecited!
Thank you
EDIT 1: Here are the results I got on small numbers like 10 and 12.
Arranged Array -> Cost (Cost is the sum of absolute difference between two successive elements)

For 10 numbers
[1, 3, 5, 2, 4, 6, 8, 10, 7, 9] 20
[2, 4, 1, 3, 5, 7, 9, 6, 8, 10] 20
For 12.
[1, 3, 5, 2, 4, 6, 8, 11, 9, 7, 10, 12] 25
[1, 3, 5, 7, 10, 12, 9, 11, 8, 6, 4, 2] 25

I need to arrange 30 such numbers where 2 <= difference <= 4 and overall cost is minimum.