Giles Bowkett wrote:
> ok, cancel that, this is not the tower of hanoi, this is splitting an
> array in half, sorting both halves, and reversing one before putting
> it back together. doh!!
>
> On 11/5/06, Giles Bowkett <gilesb / gmail.com> wrote:
> > I have an array of arrays. the interior arrays can be of any arbitrary
> > length including zero. I want to sort the array of arrays in such a
> > way that the interior arrays with the most elements are closest to the
> > middle of the main array.
> >
> > so if it comes out like this:
> > main[0] = [1, 2, 3, 4, 5]
> > main[1] = []
> > main [2] = []
> > main [3] = [1, 2]
> >
> > then that's wrong. but it's good if it looks like this:
> >
> > main[0] = []
> > main[1] = [1, 2]
> > main[2] = [1, 2, 3, 4, 5]
> > main[3] = []
> >
> > and of course it should scale with more data to produce pyramids.
> >
> > wait a minute. is this the Tower of Hanoi?
> >
> > any and all suggestions welcome. I'm going to look up the Tower of
> > Hanoi. I think that's what it is.
> >
> > --
> > Giles Bowkett
> > http://www.gilesgoatboy.org
> >
> >
>
>
> --
> Giles Bowkett
> http://www.gilesgoatboy.org

Actually, it's not even that.
If the arrays are populated in an asymetric way, then you could get one
half of the array with much higher values than the other, which might
not be what you want.

A better approach might be like this...

main_array = [
[1,2,3,1,2],
[1,1],
[],
[2],
[5,4,3,2,1,1,3],
[5,5,3,2,1],
[1]]

sorted_array = main_array.sort_by {|x| x.size}

final_array = []
sorted_array.reverse.each_with_index do |item, i|
 final_array.insert(-1*(i%2), item)
end

puts final_array.inspect

>> [[], [2], [5, 5, 3, 2, 1], [5, 4, 3, 2, 1, 1, 3], [1, 2, 3, 1, 2], [1, 1], [1]]