```On 6/29/06, James Edward Gray II <james / grayproductions.net> wrote:

> #!/usr/local/bin/ruby -w
>
> def sort(array)
>    recursive_sort(array, [])
> end
>
> def recursive_sort(unsorted, sorted)
>    # find the lowest element
>    lowest = nil
>    unsorted.each do |item|

This line (following) is the one that hung me.

>      if lowest == nil || item < lowest

After many iterations of various attempts, embarassingly I picked the
worst and most incomplete to post. I get it now somewhat, though the
'aha!' moment is still not hitting.  I'll attempt to analyze.  Your
looking for the item that is smaller (or less then) then nil.  How can
any of the items be smaller then nil ?  I know I'm missing something
here, but my thoughts were locked into comparing item < item, This is
why one of the attempts made went like this :

unsorted.each do |x|
unsorted.reverse_each do |y|
if x < y
............

>        lowest = item
>      end
>    end

Yep, I'm good at push.

>    # add it to our sorted list
>    sorted.push(lowest)

This was explained previously to me
>    # make a new unsorted list, minus the low guy
>    new_unsorted = [ ]
>    unsorted.each do |item|

item == lowest meaning that there was already something assigned to lowest ?

>      if added == false and item == lowest
>      else
>        new_unsorted.push(item)
>      end
>    end
>
>    # return sorted list if we are done, or recurse to keep sorting
>    if new_unsorted.size == 0
>      sorted
>    else
>      recursive_sort(new_unsorted, sorted)
>    end
> end
>
> list = ['zeta', 'beta', 'alpha', 'beta']
> puts sort(list)
>
> __END__
>
> Hope that helps.
>
> James Edward Gray II
>
It helps yes, thank you very much.  Wish I would have came up with it
myself.  I'll need to find a tougher sort to attempt at some point.
Meanwhile Chris is not letting up and with 4 more chapters to go I
have my work cut out for me.

Stuart

```