#!/usr/bin/perl

%foursomes = ();
%answers = ();

while (<>) {
   chomp;
#--- Get rid of leading and trailing whitespace; force to lower-case.
   s/^\s+//g;
   s/\s+$//g;
   next if length($_) < 4;
   $logos = lc($_);

   $ul = length($logos) - 4;  # Upper Limit
   for ($i = 0; $i <= $ul; $i++) {
      $tetrad = substr($logos, $i, 4);
      $foursomes{$tetrad}++;
      # We need store only the first solution for each tetrad.
      $answers{$tetrad} = $logos  if $foursomes{$tetrad} == 1;
   }
}

#--- Produce the output files.
open(Q, ">questions") or die "Huh? $!";
open(A, ">answers") or die "Huh? $!";
foreach $k (sort keys %foursomes) {
   next unless $foursomes{$k} == 1;
   print Q "$k\n";
   print A "$answers{$k}\n";
}
close Q; close A;


