1. Lucius; median

Lucius,

Very classy apology--exactly the tone I've been hoping for on this list.  We
all step over the line sometimes, we show ourselves to be decent, honoable
people by taking ownership of our mistakes and making amends.  You have
given us an excellent example.

Thank you also for your excellent info on math.  Two added points:

1.  As well as the overflow problem you explained

    function abs(atom x)
        return sqrt(x*x)
    end function

will run *significantly* slower than

     function abs(atom x)
         if x<0 then
             return -x
         else
              return x
         end if
     end function

2.  With regard to medians,  your thoughts on sorting are right on the
money.
     But the code for accessing the middle element needs adjustment:

    function median(seqeunce x)
        integer len
        len=length(x)
        if len=0 then return 0 end if
        if len>2 then  x=sort(x) end if
        if remainder(len,2)=1 then
               return x[(len+1)/2]
        else
                return (x[len/2]+x[len/2+1])/2
        end if
    end function

    For an odd number of elements the statistical median is the middle
element (element 5 of a 9-element sequence), but for an even number the
statistical median is the average (arithmetic mean) of the two middle
elements (elements 5 and 6 of a 10-element sequence.)

-- Mike Nelson

new topic     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu