Python (golfing, and assuming we want to mutate the input list)
def f(x):x[:]=[x[i+i%2*len(x)>>1]for i in range(len(x))]
The idea is to use as index
(i // 2) + (((i % 2) * len(x)) // 2)
We can however factor //2 so we get
//2
(i + (i % 2) * len(x)) // 2
Then we can use right shift >> to get rid of parenthesis to the final
>>
i + i % 2 * len(x) >> 1
A solution just returning the shuffled array instead could be:
f=lambda x:[x[i+i%2*len(x)>>1]for i in range(len(x))]
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Python (golfing, and assuming we want to mutate the input list)
The idea is to use as index
We can however factor
//2
so we getThen we can use right shift
>>
to get rid of parenthesis to the finalA solution just returning the shuffled array instead could be: