aboutsummaryrefslogtreecommitdiff
path: root/challenge-200
diff options
context:
space:
mode:
authorLoneWolfiNTj <Hatley.Software@gmail.com>2023-01-22 13:25:17 -0800
committerLoneWolfiNTj <Hatley.Software@gmail.com>2023-01-22 13:25:17 -0800
commita51df1084746b8933569ba2cc60244ba5f2da816 (patch)
treec8c4c017c4b6dca79febdaac3adddc6982fd67c6 /challenge-200
parent0c2c33a327dfca05bf91112b6d78d4c598176855 (diff)
downloadperlweeklychallenge-club-a51df1084746b8933569ba2cc60244ba5f2da816.tar.gz
perlweeklychallenge-club-a51df1084746b8933569ba2cc60244ba5f2da816.tar.bz2
perlweeklychallenge-club-a51df1084746b8933569ba2cc60244ba5f2da816.zip
Added some comments.
Diffstat (limited to 'challenge-200')
-rwxr-xr-xchallenge-200/robbie-hatley/perl/ch-1.pl16
1 files changed, 8 insertions, 8 deletions
diff --git a/challenge-200/robbie-hatley/perl/ch-1.pl b/challenge-200/robbie-hatley/perl/ch-1.pl
index 789427c264..19dab4fd9b 100755
--- a/challenge-200/robbie-hatley/perl/ch-1.pl
+++ b/challenge-200/robbie-hatley/perl/ch-1.pl
@@ -44,14 +44,14 @@ sub get_arith_slices($array_ref){
my @slices = ();
my @arith_slices = ();
my $size = scalar @array;
- my @masks = (0..((2**$size)-1));
- foreach my $mask (@masks){
- my @slice = ();
- for ( my $idx = 0 ; $idx <= $#array ; ++$idx ){
- my $yesno = ($mask/2**($size-$idx-1))%2;
- if ($yesno) {push @slice, $array[$idx]}}
- push @slices, \@slice;}
- foreach my $slice_ref (@slices){
+ my @masks = (0..((2**$size)-1));
+ foreach my $mask (@masks){ # For each possible mask,
+ my @slice = (); # create a slice.
+ for ( my $idx = 0 ; $idx <= $#array ; ++$idx ){ # For each index in @array,
+ my $yesno = ($mask/2**($idx))%2; # examine corresponding binary digit in mask,
+ if ($yesno) {push @slice, $array[$idx]}} # and do-or-don't include $array[$idx] in @slice,
+ push @slices, \@slice;} # depending on whether digit is 0 or 1.
+ foreach my $slice_ref (@slices){ # But only return slices that are arithmetic.
if (is_arith($slice_ref)) {push @arith_slices, $slice_ref}}
return @arith_slices;}