#!/afs/athena/contrib/perl/p

$|=1;
$n = 4;
while(<>){
#print("learn> ");
#$_ = (<STDIN>);
    next if $_ eq "\n";
@letters = split(//);
@pre =();
for $i (0..$n-1){
    push(@pre, "\n");
}
for $a (@letters){
    $ind = '';
    foreach $p (@pre){
	$ind .=$p;
    }

    $ARR{$ind} .= $a;
    shift(@pre);
    push(@pre, $a);
}
prin
}
while(1){
@pre =();
for $i (0..$n-1){
    push(@pre, "\n");
}
$a = '';
while($a ne "\n"){
    $ind = '';
    foreach $p (@pre){
	$ind .=$p;
    }
    $a = substr($ARR{$ind}, rand(length($ARR{$ind})), 1);
    shift(@pre);
    push(@pre, $a);
    print($a);
}
}
