in reply to Re: Merge lists of ordered strings into canonical ordering
in thread Merge lists of ordered strings into canonical ordering

Very interesting! It took me a while to figure out what you were doing here - basically just assuming that the next in the sequence must be found at the start of the remaining options, choosing one that is either the most occurrences at starts of remaining lists or first seen, removing it from the options, then repeat? It seems like you can simplify that a bit though. (I'm not sure what the 1e9 was about unless that was from an earlier attempt?)
sub fancy_algorithm { my @args= @_; p @args; my @order; while (@args) { my ($pick, %score, %seen_order); my $see = 1; $seen_order{$_} += $see++ for map @$_, @args; for (@args) { my $n= --$score{$_->[0]}; $pick= $_->[0] if !defined $pick or $n < $score{$pick} or $n == $score{$pick} && $seen_order{$_->[0]} < $seen_ord +er{$pick}; } push @order, $pick; $_ = [ grep $pick ne $_, @$_ ] for @args; @args = grep @$_, @args; } return \@order; }

It seems to work in every case I've tried, though it gives less ideal results with:

my @lists= ( [qw( S T )], [qw( S U )], [qw( Y Z )], [qw( X Y )], [qw( W X )], [qw( V W )], [qw( U V )], ); # S U V W X Y T Z