Re: Tasks
- Posted by Jiri Babor <J.Babor at GNS.CRI.NZ> Aug 15, 2000
- 485 views
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})