#!/usr/bin/perl

$FRAG_LEN = 4;
$DUPLICATE = "";

while (<>) {
  chomp;
  $_ = lc;
  next if /[^a-z]/;
  next if $seen{$_}++;

  my %fseen;
  for my $p (0 .. length() - $FRAG_LEN) {
    my $frag = substr($_, $p, $FRAG_LEN);
    next if $fseen{$frag}++;
    if (exists $f{$frag}) { $f{$frag} = $DUPLICATE }
    else { $f{$frag} = $_ }
  }
}

open Q, ">", "questions" or die $!;
open A, ">", "answers" or die $!;
while (my ($q, $a) = each %f) {
  next if $a eq $DUPLICATE;
  print Q $q, "\n";
  print A $a, "\n";
}

1;

