in reply to Re: scrambling all letters in a word until all combinations are found
in thread scrambling all letters in a word until all combinations are found
Thank you for your help. With your code there, it appears it does exactly what I needed. But when I changed it to read in my partial dictionary file, it started to throw out words that it couldn't have matched.
resulted in:#!/usr/bin/perl use strict; use warnings; use CGI qw/:standard/; print header, start_html(); my $letters = 'balphe_'; my (%lhash, @solutions, $blanks, $bcopy, $l); $blanks++ while $letters =~ s/[^a-z]//; $lhash{$_}++ for split //, $letters; open (DICT, "dict/dict1.txt") or die "error :!"; while (<DICT>) { $bcopy = $blanks; my %whash; chomp; $whash{$_}++ for split //; for $l (keys %whash) { no warnings; last if $lhash{$l} < $whash{$l} && ($bcopy -= $whash{$l} - $lhash{$l}) < 0; } push @solutions, $_ if $bcopy > -1; } print join "\n", sort {length($b) <=> length($a) || $a cmp $b} @solutions; exit; __DATA__ alpha beta gamma delta epsilon
It matched "behalf" which, with the letters, couldn't have matched. Any suggestions?alephs behalf blahes bleach chapel Alpha Calpe abele abler ables albae + aleph amble ample apple babel bagel baled baler bales basel bathe be +ach belah belay belch belga bella blade blahs blame blare blase blaze + bleak blear bleat bleep bohea cable caleb chape cheap chela chelp Ab +el Ahab Alba Cape Cheb abbe abed abeg abet able ably ache ahem aiel a +ile alae alap albs alec alee ales alex aloe alps aped aper apes apex +apse axel axle babe bade bael bagh baht bail bake bald bale bali balk + ball balm bane bare base bash bate bawl bead beak beam bean beat bea +u beep bela bell belt bema beth bhan bile blab blah
|
|---|