From: 7stud -- Date: 2007-10-03T21:50:26+09:00 Subject: Re: Searching through a sorted array Axel Etzold wrote: > > # some example > len=10**8 > a=(1..len).to_a > b=5*len/2 > cond='lower_index>10' > r=a.find_lower_index(cond) > cond='upper_index<100' > s=a.find_upper_index(cond) > p r,s > p a[r] > p a[s] When I use this code: a = [2, 4, 6, 8] cond='lower_index>0' r=a.find_lower_index(cond) cond='upper_index<2' s=a.find_upper_index(cond) p r,s p a[r] p a[s] I get this output: 3 1 8 4 The output appears to be backwards, since the lower index would be 1 and the upper index would be 3. And it's a little bit puzzling why a search would be needed to find an index in an array that is greater than 0. I can tell you the answer without searching: it's 1. The same goes for the upper index: if the cond = "upper index < 2", then the upper index is 1. -- Posted via http://www.ruby-forum.com/.