On Wed, 26 Sep 2007 17:57:16 +0900, Harry Kakueki wrote:

> 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

Hmm, that fails if I add "db 20 is on sv 2", which should retain "server 2
handles db 18 through 18" but also add "srver 2 handles db 20 through 20".
I can't quite follow what it's doing but I'm going to have to study that
more; map is a powerful tool in general.

-- 
Jay Levitt                |
Boston, MA                | My character doesn't like it when they
Faster: jay at jay dot fm | cry or shout or hit.
http://www.jay.fm         | - Kristoffer