Here's my solution. Nice and short. I had also forgotten about sequences
which appear twice in the same word. $seq{$1} ne $_ was a quick fix for
that bug.
Ronald
#!/usr/local/bin/perl -w
use strict;
my %seq;
open Q, ">questions" or die "Can't open 'questions': $!\n";
open A, ">answers" or die "Can't open 'answers': $!\n";
while (<>) {
chomp;
while (/(?=(.{4}))/g) {
if (exists $seq{$1} and $seq{$1} ne $_) {
$seq{$1} = 1;
} else {
$seq{$1} = $_;
}
}
}
for (sort (grep {$seq{$_} ne '1'} keys %seq)) {
print Q "$_\n";
print A "$seq{$_}\n";
}
__END__
|