But we aren't interested in sorting numbers, we are interested in finding the smallest. Therefore his can NOT be the fastest. The fastest sorting algorithm known is Theta(Nlg(N)) meaning, if there are N elements to sort, it takes N * log2(N) comparisons to sort it. Using a simple while() loop to go through all the entries and find the smallest is Theta(N) (it takes N comparisons). You're right, his way is the best way to sort it, but sorting is NOT the best way to find the smallest.

Edit:
The fastest (least complex) way to do this is using:
Code:
alias min {
  var %m = $1, %i = $0
  while (%i > 1) {
    if ($eval($ $+ %i,2) < %m) %m = $ifmatch
    dec %i
  }
  return %m
}

Thats similar to Rich's except it is slightly faster. Rich checks from $0 through 1. It is not necessary to check 1 ($1), because the inital value assigned to the minimum, we only have to check from $0 to 2 ($2). What I mean is, Rich's tests if ($1 < $1) which we know is never going to be true, so there is no need to test it.

Last edited by codemastr; 17/08/03 08:12 PM.