rbandrews: (Lambda)
[personal profile] rbandrews
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?

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

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

Profile

rbandrews: (Default)
rbandrews

July 2024

S M T W T F S
 123456
78910111213
14151617181920
212223242526 27
28293031   

Style Credit

Page generated Jun. 21st, 2025 04:38 pm
Powered by Dreamwidth Studios

Expand Cut Tags

No cut tags