What I tried so far in Perl
:
use strict;
use warnings;
use Algorithm::Combinatorics qw(permutations);
die "First argument should be a dict\n" unless $ARGV[0] or die $!;
open my $fh, "<", $ARGV[0] or die $!;
my @arr = <$fh>;
my $h = {};
map { chomp; $h->{lc($_)} = [] } @arr;
foreach my $word (@arr) {
$word = lc($word);
my $chars = [ ( $word =~ m/./g ) ];
my $it = permutations($chars);
while ( my $p = $it->next ) {
my $str = join "", @$p;
if ($str ne $word && exists $h->{$str}) {
push @{ $h->{$word} }, $str
unless grep { /^$str$/ } @{ $h->{$word} };
}
}
if (@{ $h->{$word} }) {
print "$word\n";
print "\t$_\n" for @{ $h->{$word} };
}
}
END{ close $fh; }
There's maybe some possible improvement for speed, but it works.
I use French dict from words
archlinux
package.
EXAMPLE
$ perl annagrammes.pl /usr/share/dict/french
abaissent
absentais
abstenais
abaisser
baissera
baserais
rabaisse
(...)
NOTE
To installl the perl module :
cpan -i Algorithm::Combinatorics