# 
# Alan Voss schreef:
# > I decided to take a regex approach--  feed it the name of a dictionary file 
# > as the argument...  -Alan
# > 
# >   /(\w{4})(?{$sequences{lc $1}++; $goodones{lc $1} = $_})(?!)/g;
# 
# This isn't quite up to specs:
# 
# $ cat dict
# lightweight
# alfalfa
# $ perl voss.pl dict
# $ grep -c ight questions 
# 0
# $ grep -c alfa questions 
# 0
# 
# Also, your solutions stores a word for all sequences encountered in
# %goodones, even those which occur often. As I had some huge word lists,
# I took care to store only those words which I might need later.
# 
# 
# 
#!perl -w
use strict;

# $n is the length of the sequences. Lower $n's give more interesting
# results for large dict files
my $n=4;
  
my %seen;
while ($_ = lc<>) {
    chomp;
    my %in_this_word;
    while (/(?=(\w{$n}))./g) {
        next if $in_this_word{$1}++;
        $seen{$1} = exists $seen{$1} ? undef : $_;
    }
}

open QUESTIONS, '>questions' or die $!;
open ANSWERS, '>answers' or die $!;

while (my ($four,$word) = each %seen) {
    next unless defined $word;
    print QUESTIONS "$four\n";
    print ANSWERS "$word\n";
}
