Skip to content

Commit 8edad69

Browse files
authored
fish: reduce code (#449)
* Init the deck without a loop * Loop in fisher_yates_shuffle() can be written without a "next" statement; swap if unequal
1 parent 229c940 commit 8edad69

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

bin/fish

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,7 @@ sub fisher_yates_shuffle { # From The Perl Cookbook, recipe 4.17
149149
my $i;
150150
for($i=@$array; --$i;) {
151151
my $j=int rand ($i+1);
152-
next if $i==$j;
153-
@$array[$i,$j]=@$array[$j,$i];
152+
@$array[$i,$j] = @$array[$j,$i] if $i != $j;
154153
}
155154
}
156155

@@ -180,8 +179,7 @@ if ($status=~/^y/i) {
180179
print "Press <return>"; $status=<STDIN>;
181180
}
182181

183-
@DECK=split(//, 'A'x4 . 'K'x4 . 'Q'x4 . 'J'x4);
184-
foreach(1..4) {foreach(2..10) { push(@DECK, $_) } }
182+
@DECK = qw(A K Q J 10 9 8 7 6 5 4 3 2) x 4;
185183
fisher_yates_shuffle(\@DECK);
186184

187185
foreach(1..7) {

0 commit comments

Comments
 (0)