Even if Perl is in dict, starting at perl is faster since it has fewer adjacent ladder words, so search tree starts less bushy (and on average will reamain so), and more next-move-win states since ping has more adjacency.
Most of the time shouldn't be in file scan unless your machine has no disk cache or the program ran correctly the first and only time! With cache, I am seeing 124ms on building %is_word with a small dict, twice as much loading half dozen dicts including moby. Oh wait, I made one small tweak to achieve that ...
my $n = length($start ); # add ...
while () {
chomp();
next unless length() == $n; # add
$is_word{lc($_)}++;
}
the cost of rebalancing the much smaller hash is much less. To build a full dict is more like 5000ms, so yes, tha would be dominating. Don't hash what you don't need!
maybe tonight or weekend i can bench some otheralgos, eg the meet in the middle / alternate ends strategy and the grep f($word), keys tactic. Need something better to try to answer if there is ANY connection from
ladder
ramrod
starting from ping, with a gob of dicts loaded, I still don't to theoretical 3-move 4-ladder, but this is cute -
perl
pern
penn
peng
ping
not that I'd allow many of those in a game of Scr@bbl3* either.
Read More