From: "Eric I." Date: 2008-07-17T06:39:52+09:00 Subject: Re: The next number that is not in an array On Wed, Jul 16, 2008 at 5:01 PM, Tim Conner wrote: > I want to increment the current value of a variable to the next number > that does not appear in an array of restricted numbers. > e.g. > restricted_numbers = [2,3,4,5,8,10,15,29] > > if the variable is currently storing 11 then I want to increment it to > 12, > however if the variable is currently storing 1 then I want to increment > it to 6. > > How is this done in ruby? How about: begin value += 1 end while restricted_numbers.member?(value) Depending on the size of your list of restricted values, you may want to use a Set rather than an Array, as it can test membership much more efficiently. Eric ==== LearnRuby.com offers Rails & Ruby HANDS-ON public & ON-SITE workshops. Please visit http://LearnRuby.com for all the details.