From: Xavier Noria Date: 2007-08-03T11:46:01+09:00 Subject: Re: Determining the common prefix for several strings El Aug 3, 2007, a las 4:41 AM, Xavier Noria escribi�: > 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 Ah, and the prefix can be extracted from the original string instead of the split: splits = items.map {|i| i.split(//)} (0...splits.length).each do |i| if splits.map {|s| s[i]}.uniq.length != 1 puts items.first[0, i] break end end -- fxn