From 40c2fdb4a4792a87c1e1d44d5e744583ed794e2b Mon Sep 17 00:00:00 2001 From: jluehrs2 Date: Thu, 31 Jan 2008 20:02:13 -0500 Subject: add a function to get a list of all permutations of a string --- lib/Games/Word.pm | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'lib/Games/Word.pm') 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 - ??? -- cgit v1.2.3-54-g00ecf