diff options
author | jluehrs2 <jluehrs2@uiuc.edu> | 2008-01-31 20:02:13 -0500 |
---|---|---|
committer | jluehrs2 <jluehrs2@uiuc.edu> | 2008-01-31 20:02:13 -0500 |
commit | 40c2fdb4a4792a87c1e1d44d5e744583ed794e2b (patch) | |
tree | 9e719299851eaddf26a3f36f8dc115965a80e0fb | |
parent | 39968282dd9dc5f9276f8fea507ce4d306c46e1d (diff) | |
download | games-word-40c2fdb4a4792a87c1e1d44d5e744583ed794e2b.tar.gz games-word-40c2fdb4a4792a87c1e1d44d5e744583ed794e2b.zip |
add a function to get a list of all permutations of a string
-rw-r--r-- | lib/Games/Word.pm | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/lib/Games/Word.pm b/lib/Games/Word.pm index d9f4801..89610d4 100644 --- a/lib/Games/Word.pm +++ b/lib/Games/Word.pm @@ -2,7 +2,7 @@ package Games::Word; require Exporter; @ISA = qw/Exporter/; -@EXPORT_OK = qw/random_permutation is_permutation/; +@EXPORT_OK = qw/random_permutation is_permutation all_permutations/; use strict; use warnings; @@ -36,6 +36,14 @@ sub is_permutation { return eq_deeply(\@word_letters, bag(@perm_letters)); } +sub all_permutations { + my $word = shift; + my @ret = (); + push @ret, random_permutation($word, $_) + for (0..(factorial(length($word)) - 1)); + return @ret; +} + =head1 NAME Games::Word - ??? |