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); }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: One for the weekend: challenge
by karavelov (Monk) on Jun 01, 2008 at 21:30 UTC | |
Re^2: One for the weekend: challenge
by BrowserUk (Patriarch) on Jun 01, 2008 at 15:59 UTC | |
by Anonymous Monk on Jun 01, 2008 at 16:55 UTC | |
Re^2: One for the weekend: challenge
by Anonymous Monk on Jun 03, 2008 at 14:09 UTC |
In Section
Meditations