#!/usr/bin/perl use strict; use warnings; my $dictionary = 'words.txt'; open(my $fh, '<', $dictionary) or die "Unable to open '$dictionary' fo +r reading: $!"; my %data; while (<$fh>) { chomp $_; my $str = join '', sort map lc(), split //; push @{$data{$str}}, $str; } my $letters = $ARGV[0] or die "Usage: $0 <set_of_letters>"; $letters = join '', sort map lc(), split //, $letters; if (! exists $data{$letters}) { print "Could not find any matching words\n"; } else { for my $word (@{$data{$letters}}) { print "$word\n"; } }
Update: This code is untested. It stores everything in memory, but as kyle shows - that can easily be modified if needed. The algorithm essentially changes all words in the dictionary to the same format so you can perform a hash lookup. For instance:
art = art tar = art rat = art
Cheers - L~R
In reply to Re: Found a word from a set of letters
by Limbic~Region
in thread Found a word from a set of letters
by vnpenguin
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |