From: Harry Kakueki Date: 2007-09-26T17:57:16+09:00 Subject: Re: Detecting number ranges On 9/26/07, Jay Levitt wrote: > I had to write a script this evening to take an unsorted input file of the > form: > > database 1 is on server 3 > database 8 is on server 7 > ... > > and output it in the form: > > server 3 handles database 1 through 7 > server 7 handles database 8 through 11 > > Does this do it? fp_arr = ["db 11 is on sv 3","db 9 is on sv 7","db 13 is on sv 3","db 12 is on sv 3","db 8 is on sv 7","db 18 is on sv 2"] nums,info = [],{} fp_arr.each {|x| nums << x.scan(/\d+/)} sv = nums.map{|x| x[1]}.uniq sv.each {|t| info[t] = nums.select{|x| x[1] == t}.sort.map {|a| a[0]}} info.keys.sort.each {|j| print "server #{j} handles database #{info[j][0]} through #{info[j][-1]}\n"} #server 2 handles database 18 through 18 #server 3 handles database 11 through 13 #server 7 handles database 8 through 9 Harry -- A Look into Japanese Ruby List in English http://www.kakueki.com/