From: Robert Dober Date: 2008-07-17T23:06:51+09:00 Subject: Re: The next number that is not in an array On Thu, Jul 17, 2008 at 3:44 PM, Robert Dober wrote: >> true while restricted_numbers.include?(n+=1) > I think there is a typo in here ;) > > Did you mean > > 42 while restricted_numbers.include?( n+= 1 ) > > of course you did. > > Now to add injustice to injury ;) What about n = ([*n.succ..rn.max.succ]-rn).min || n.succ This will be about 10 times slower than David's beautiful code. However in some extreme cases, e.g. very densely populated rn arrays this functional approach becomes more interesting. If rn is [*1..1_000] the functional code runs 50 times faster, and if you have to jump over an restricted numbers array of [*1..10_000] the functional code runs 500 times faster. So maybe just in case you can afford the extra runtime for the "normal" case you can assure nice performance in edge cases by the functional approach. Cheers Robert -- http://ruby-smalltalk.blogspot.com/ --- AALST (n.) One who changes his name to be further to the front D.Adams; The Meaning of LIFF