use strict; use warnings; use Algorithm::Combinatorics qw(permutations); use List::Set qw(uniq intersection); use Readonly; use ActiveState::Prompt qw( prompt ); #JUMBLE TOOL V1.1.2 Readonly::Scalar my $NULL_STRING => q(); Readonly::Scalar my $WORDFILE => $ARGV[0] || Win32::GetShortPathName( 'C:\Documents and Settings\Bill\perl\hangman\web2.txt' ); open my $WORDLIST, '<', $WORDFILE or die "Unable to open word list $WORDFILE\n"; warn "Loading word list\n"; my @wordlist; while (my $word = <$WORDLIST>){ chomp $word; push @wordlist, uc $word; } close $WORDLIST; @wordlist = uniq(@wordlist); while (1) { my $pattern = prompt( q(Enter JUMBLE ('q[uit]' to exit): ) ); exit if $pattern =~ /^Q(:?UIT)?$/i; my @candidates = permutations( [split //, uc $pattern] ); @candidates = map { join $NULL_STRING, @$_ } @candidates ; @candidates = uniq(@candidates); my $word_length = length $pattern; my @wordlist1 = grep {$word_length == length $_} @wordlist; print "\nSOLUTIONS:\n\n"; print join "\n", intersection([@wordlist1],[@candidates]); print "\n\n"; } =head1 JUMBLE - Tool for solving 'JUMBLE' puzzles =head1 SYNOPSIS jumble [wordlist.txt] =head1 DESCRIPTION This program can solve most JUMBLE puzzles by generating all permutations of the puzzle text and looking for each in a list of common English words. It displays a list of all matching words. =head1 OPTIONS The only option is an alternate wordlist file. =head1 RETURN VALUE tbsl =head1 DIAGNOSTICS Unable to open I =head1 EXAMPLES tbsl =head1 ENVIRONMENT No ENVIROMENT variables are used by this program =head1 FILES The wordlist.txt data file contains a list of common English words in plain ASCII text. They are stored one word per line. Capitalization does not matter. Several suitable files are currently available at perl.plover.com/qotw/words =head1 CAVEATS None =head1 BUGS No known bugs =head1 RESTRICTIONS Use is currently restricted to ActiveState installations on Windows. Replace prompt module for use on other systems. =head1 NOTES This program can be used for finding single-word anagrams. =head1 SEE ALSO No other references are available. =head1 AUTHOR BiLL K Smith =head1 COPYRIGHT AND LICENSE Copyright 2011 by William K. Smith This program is free software; you may redistribute it and/or modify it under the same terms as Perl itself. =head1 HISTORY This is the first released version of this program. =cut