# Hi
# 
# I decided that capitalisation in this quiz was irrelevant, so if the
# word is long enough to be considered, I lowercase it before any other
# processing.
# 
# It seemed to me that substr was probably going to be a better way of
# splitting out fragments than trying to use a regex.  For this kind of
# thing where you know exactly which fragment you want and where it starts
# and finishes, substr is always faster than a regex anyway.
# 
# 
# #!/usr/bin/perl
# 
use strict;
use warnings;

my %cache;

while (my $word = <>) {
  chomp $word;
  next unless length $word > 3;
  $word = lc $word;
  my $bits = -4 + length $word;
  for my $i (0 .. $bits) {
    my $frag = substr $word, $i, 4;
    $cache{$frag} = exists $cache{$frag} ? "**DUP**" : $word;
  }
}

open OUT1, ">questions" or die "Can't open questions $!\n";
open OUT2, ">answers" or die "Can't open answers $!\n";

for (sort keys %cache) {
  next if $cache{$_} eq "**DUP**";
  print OUT1 "$_\n";
  print OUT2 "$cache{$_}\n";
}

__END__

andrew
--=20
Gemini: (May 21 - June 21)
It's been almost three decades, but you think you're finally beginning
to recover from the long, national nightmare of Vietnam movies.

--raC6veAxrt5nqIoY
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iD8DBQE9+0k84x3z39L355MRAp0NAJ0dPky/9Gdn8xoGYEpmr/TvT3IwiwCglCPo
rDDzIKyaXMtcFdygVoy5sAk=
=/ZXd
-----END PGP SIGNATURE-----

--raC6veAxrt5nqIoY--
