in reply to Finding Consensus String

This appears to meet the spec?

#! perl -slw use strict; sub consensus { my( $aref ) = @_; my $result; my $xor = $aref->[0]; $xor ^= $_ for @{ $aref }[ 1 .. $#$aref ]; for my $o ( 0 .. length( $xor ) -1 ) { if( substr $xor, $o, 1 eq chr(0) ) { $result .= substr $aref->[0], $o, 1; } else { my %c; $c{ substr $_, $o, 1 }++ for @{ $aref }; my @sorted = sort{ $c{ $b } <=> $c{ $a } } keys %c; my $add = join '', grep{ $c{ $_ } == $c{ $sorted[ 0 ] } } +@sorted; $add = "[$add]" if length( $add ) > 1; $result .= $add; } } return $result; } my @sets = ( [ qw[AAAAA ATCGA ATAAA] ], [ qw[AAAAA AACGA ATAAA ATAAA] ], [ qw[ACCGTA ATCGTA ACTGGA ATCCGA ] ], ); print "[@$_] : ", consensus( $_ ) for @sets; __END__ P:\test>500962 [AAAAA ATCGA ATAAA] : ATAAA [AAAAA AACGA ATAAA ATAAA] : A[AT]AAA [ACCGTA ATCGTA ACTGGA ATCCGA] : A[TC]CG[TG]A

Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
"Science is about questioning the status quo. Questioning authority".
The "good enough" maybe good enough for the now, and perfection maybe unobtainable, but that should not preclude us from striving for perfection, when time, circumstance or desire allow.