Re: Tasks

new topic     » goto parent     » topic index » view thread      » older message » newer message

Good morning, Hawke'.

I cannot do them as one-liners, but using your (Carl's?) suggestion, two
statements suffice.
The code below is not terribly efficient and is applicable to one-dimensional
sequences only.

jiri

--  minmax.ex
--  jiri_babor at hotmail.com
--  00-08-15

function min(sequence s)
    while length(s)>1 do s=s[1]*(s[1]<=s[2])+s[2]*(s[2]<s[1])&s[3..length(s)]
end while
    return s[1]
end function

function max(sequence s)
    while length(s)>1 do s=s[1]*(s[1]>=s[2])+s[2]*(s[2]>s[1])&s[3..length(s)]
end while
    return s[1]
end function

-- test --------------------------------------------------------------
? min({4.1, -77.2, 111, 15.3})
? max({4.1, -77.2, 111, 15.3})

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu