in reply to
One for the weekend: challenge
This took about two hours to write, through three iterations to get reasonable performance (under one second on a Sempron 3000). I'm sure I'll have issues with the "maintainability" score :)
#!perl
use strict;
my %dict;
@ARGV = qw( d.dict d.input );
while(<>) # read in both files, load dict on first, match on second
{
chomp;
(my $d = lc) =~ tr|a-z"/-|57630499617851881234762239|d;
$ARGV eq 'd.dict' ? push @{$dict{$d}}, $_ : match($d, 0, "$_:");
}
sub match # (to match, last was digit, matches)
{
my ($in, $digit, @have, $cnt) = @_;
$in eq '' and return print "@have\n"; # have full match
for my $k (map { substr $in, 0, $_ } 2..length $in)
{
match(substr($in, length $k), !++$cnt, @have, $_) for @{$dict{$k}}
+;
}
$cnt or $digit or match(substr($in, 1), 1, @have, substr $in, 0, 1);
}