summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjluehrs2 <jluehrs2@uiuc.edu>2008-01-31 20:02:34 -0500
committerjluehrs2 <jluehrs2@uiuc.edu>2008-01-31 20:02:34 -0500
commit6a7b61d22dead93a18b56fc409a9b4be7034563a (patch)
tree1dbf3f37950908b8482c5fc6ce33e1eb68404a0c
parent40c2fdb4a4792a87c1e1d44d5e744583ed794e2b (diff)
downloadgames-word-6a7b61d22dead93a18b56fc409a9b4be7034563a.tar.gz
games-word-6a7b61d22dead93a18b56fc409a9b4be7034563a.zip
add an anagrams() function to get anagrams of a word
-rw-r--r--lib/Games/Word/Wordlist.pm9
1 files changed, 9 insertions, 0 deletions
diff --git a/lib/Games/Word/Wordlist.pm b/lib/Games/Word/Wordlist.pm
index 399aff4..f7f9716 100644
--- a/lib/Games/Word/Wordlist.pm
+++ b/lib/Games/Word/Wordlist.pm
@@ -2,6 +2,8 @@
package Games::Word::Wordlist;
use strict;
use warnings;
+use Games::Word qw/all_permutations/;
+use List::MoreUtils qw/uniq/;
sub new {
my $class = shift;
@@ -105,6 +107,13 @@ sub _each_word {
return $self->_each_word_nocache(@_);
}
+sub anagrams {
+ my $self = shift;
+ my $word = shift;
+
+ return uniq grep { $self->is_word($_) } all_permutations($word);
+}
+
=head1 NAME
Games::Word::Wordlist - ???