From: Eric Promislow Date: 2007-08-06T01:40:08+09:00 Subject: Re: Determining the common prefix for several strings On Aug 3, 3:30 pm, Eric Promislow wrote: > The obligatory solution usingzip... > > # data contains a list of strings > aa = data.map{ |x| x.split(//)} > bz = aa[0].zip(*(aa[1 .. -1])).map{ |x| x.join("")} > target = bz.index( bz.find{ |x| x.squeeze.size != 1}) > answer = (target.nil? ? aa[0] : > target >= 1 ? aa[0][0 .. target - 1] : > []).join("") > > - Eric Doh! This isn't correct. It's hard to improve over Michael's routine back in the initial response. You need to find any one of the shortest strings, remove it, and use that instead of aa[0] as above.