From 9250b3fbd3babd24e9ee3a21f804519b485f7a20 Mon Sep 17 00:00:00 2001 From: jluehrs2 Date: Sat, 2 Feb 2008 13:42:32 -0500 Subject: add subwords_of to return only the subpermutations that are actually words --- lib/Games/Word/Wordlist.pm | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) 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 - ??? -- cgit v1.2.3