rbandrews: (Lambda)
rbandrews ([personal profile] rbandrews) wrote2009-03-01 12:16 am

The smallest smallest

In Ruby:
def smallest a, b=nil, *c
  b ? smallest( (a<b ? a : b), *c ) : a
end

smallest(9,8,5,2,3) # is 2
Can anyone do better?

[identity profile] heptadecagram.livejournal.com 2009-03-02 09:45 am (UTC)(link)
def smallest *all
    all.sort[0]
end

Then again, yours is O(n) versus my O(n log n)