summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjluehrs2 <jluehrs2@uiuc.edu>2008-02-02 05:41:03 -0500
committerjluehrs2 <jluehrs2@uiuc.edu>2008-02-02 05:41:03 -0500
commita62c47ae7885891b7778d26cb81dd25fe82973af (patch)
treecc1f0cdc7612f24b2ac8659442f500bd827674fa
parent65bb08f71b07ea1794e91c351e7959d24387e0a7 (diff)
downloadgames-word-a62c47ae7885891b7778d26cb81dd25fe82973af.tar.gz
games-word-a62c47ae7885891b7778d26cb81dd25fe82973af.zip
add is_subpermutation and all_subpermutations to do the same thing as the substring functions, except without order mattering
-rw-r--r--lib/Games/Word.pm14
1 files changed, 13 insertions, 1 deletions
diff --git a/lib/Games/Word.pm b/lib/Games/Word.pm
index 514b4e5..46129a7 100644
--- a/lib/Games/Word.pm
+++ b/lib/Games/Word.pm
@@ -5,7 +5,8 @@ require Exporter;
@EXPORT_OK = qw/random_permutation is_permutation all_permutations
shared_letters shared_letters_by_position
random_string_from
- is_substring all_substrings/;
+ is_substring all_substrings
+ is_subpermutation all_subpermutations/;
use strict;
use warnings;
@@ -137,6 +138,17 @@ sub all_substrings {
return @substrings;
}
+sub is_subpermutation {
+ my @subword = split //, shift;
+ my @word = split //, shift;
+
+ return eq_deeply(\@subword, subbagof(@word));
+}
+
+sub all_subpermutations {
+ return map { all_permutations $_ } all_substrings shift;
+}
+
=head1 NAME
Games::Word - ???