Sorting a list, ignoring every nth element?
<p>I have a list (I can implement it as whatever type of collection gives a succinct solution) like this:</p>

<pre><code>4,1,5,2,1,3,8,1,6,4,2,3
</code></pre>

<p>The list is actually groups of 3 values and it's length will always be a multiple of 3.  There is no relationship between the first 2 values of the group and the 3rd value of the group.  </p>

<p>I would like to sort the array such that every 3rd value is left in place.  For the example I've given, the result would be:</p>

<pre><code>1,1,5,1,2,3,2,4,6,4,8,3
</code></pre>

<p>The elements with indices 0,1,3,4,6 and 7 have been sorted.  The elements with indices 2,5 and 8 have not been sorted.</p>

<p>Another way to express this is to imagine that the list is x,x,y,x,x,y,x,x,y,x,x,y and I want to sort only the xs.</p>

<p>I can write an algorithm but wonder if there is succinct way of doing this?</p>
