summaryrefslogtreecommitdiffstats
path: root/lib/Games/Word.pm
diff options
context:
space:
mode:
authorjluehrs2 <jluehrs2@uiuc.edu>2008-02-01 12:41:34 -0500
committerjluehrs2 <jluehrs2@uiuc.edu>2008-02-01 12:41:34 -0500
commit0fbcee116b0221c3985561b5cc91b4e782705b20 (patch)
treed4cf0ae4cf7978000495da95c8f457960cdba818 /lib/Games/Word.pm
parent452313f92901f9b460fd38d44630a6b47dcad748 (diff)
downloadgames-word-0fbcee116b0221c3985561b5cc91b4e782705b20.tar.gz
games-word-0fbcee116b0221c3985561b5cc91b4e782705b20.zip
minor syntax cleanups
Diffstat (limited to 'lib/Games/Word.pm')
-rw-r--r--lib/Games/Word.pm10
1 files changed, 7 insertions, 3 deletions
diff --git a/lib/Games/Word.pm b/lib/Games/Word.pm
index 89610d4..de51ad0 100644
--- a/lib/Games/Word.pm
+++ b/lib/Games/Word.pm
@@ -11,13 +11,15 @@ use Test::Deep::NoTest;
sub random_permutation {
my $word = shift;
+ my $perm_index = shift;
+
return '' if $word eq '';
use integer;
+
my $len = length $word;
- my $perm_index = shift;
$perm_index = defined($perm_index) ? $perm_index :
- int(rand(factorial($len)));
+ int rand factorial $len;
die "invalid permutation index" if $perm_index >= factorial($len) ||
$perm_index < 0;
my $current_index = $perm_index / factorial($len - 1);
@@ -38,9 +40,11 @@ sub is_permutation {
sub all_permutations {
my $word = shift;
+
my @ret = ();
push @ret, random_permutation($word, $_)
- for (0..(factorial(length($word)) - 1));
+ for 0..(factorial(length $word) - 1);
+
return @ret;
}