summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjluehrs2 <jluehrs2@uiuc.edu>2008-02-02 13:42:32 -0500
committerjluehrs2 <jluehrs2@uiuc.edu>2008-02-02 13:42:32 -0500
commit9250b3fbd3babd24e9ee3a21f804519b485f7a20 (patch)
treec05c78e08f2e58282b20d90aa1d5642be74998f9
parentc25bb1bd704d55b25d8009968d29a82ca3a45d72 (diff)
downloadgames-word-9250b3fbd3babd24e9ee3a21f804519b485f7a20.tar.gz
games-word-9250b3fbd3babd24e9ee3a21f804519b485f7a20.zip
add subwords_of to return only the subpermutations that are actually words
-rw-r--r--lib/Games/Word/Wordlist.pm13
1 files changed, 12 insertions, 1 deletions
diff --git a/lib/Games/Word/Wordlist.pm b/lib/Games/Word/Wordlist.pm
index 81f8a5b..396d4de 100644
--- a/lib/Games/Word/Wordlist.pm
+++ b/lib/Games/Word/Wordlist.pm
@@ -2,7 +2,7 @@
package Games::Word::Wordlist;
use strict;
use warnings;
-use Games::Word qw/all_permutations/;
+use Games::Word qw/all_permutations is_subpermutation/;
use List::MoreUtils qw/uniq/;
sub new {
@@ -173,6 +173,17 @@ sub words_like {
return @words;
}
+sub subwords_of {
+ my $self = shift;
+ my $string = shift;
+
+ my @words = ();
+ $self->_each_word(sub { push @words, $_[0]
+ if is_subpermutation($_[0], $string)});
+
+ return @words;
+}
+
=head1 NAME
Games::Word::Wordlist - ???