From: Xavier Noria Date: 2007-08-03T11:41:54+09:00 Subject: Re: Determining the common prefix for several strings El Aug 3, 2007, a las 4:26 AM, Xavier Noria escribi�: > min_length = items.map {|i| i.length}.min > cuts = items.map {|i| i.split(//)[0, min_length]} > cuts.transpose.each_with_index do |t, i| > if t.uniq.length != 1 > puts cuts.first[0, i].join('') > break > end > end Hmmm, too convoluted. I realized you don't need the transpose and thus the min length and cuts if you go by columns in the loop. This is the same idea only more simple: splits = items.map {|i| i.split(//)} (0...splits.length).each do |i| if splits.map {|s| s[i]}.uniq.length != 1 puts splits.first[0, i].join('') break end end -- fxn