diff options
author | jluehrs2 <jluehrs2@uiuc.edu> | 2008-02-02 05:41:03 -0500 |
---|---|---|
committer | jluehrs2 <jluehrs2@uiuc.edu> | 2008-02-02 05:41:03 -0500 |
commit | a62c47ae7885891b7778d26cb81dd25fe82973af (patch) | |
tree | cc1f0cdc7612f24b2ac8659442f500bd827674fa | |
parent | 65bb08f71b07ea1794e91c351e7959d24387e0a7 (diff) | |
download | games-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.pm | 14 |
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 - ??? |