diff options
| author | Adam Russell <adamcrussell@outlook.com> | 2025-06-08 12:36:57 -0400 |
|---|---|---|
| committer | Adam Russell <adamcrussell@outlook.com> | 2025-06-08 12:36:57 -0400 |
| commit | 4572ea480336a511dfa141605d4bf31d197002e8 (patch) | |
| tree | 3799426db6911a98853a7d7716d83fafe4c5adc6 | |
| parent | efa631ada4e63b89e590e48d14b17f69c26495be (diff) | |
| download | perlweeklychallenge-club-4572ea480336a511dfa141605d4bf31d197002e8.tar.gz perlweeklychallenge-club-4572ea480336a511dfa141605d4bf31d197002e8.tar.bz2 perlweeklychallenge-club-4572ea480336a511dfa141605d4bf31d197002e8.zip | |
initial commit
| -rw-r--r-- | challenge-324/adam-russell/blog.txt | 1 | ||||
| -rw-r--r-- | challenge-324/adam-russell/perl/ch-1.pl | 49 | ||||
| -rw-r--r-- | challenge-324/adam-russell/perl/ch-2.pl | 33 |
3 files changed, 83 insertions, 0 deletions
diff --git a/challenge-324/adam-russell/blog.txt b/challenge-324/adam-russell/blog.txt new file mode 100644 index 0000000000..4fbaa49651 --- /dev/null +++ b/challenge-324/adam-russell/blog.txt @@ -0,0 +1 @@ +http://rabbitfarm.com/cgi-bin/blosxom/perl/2025/06/08 diff --git a/challenge-324/adam-russell/perl/ch-1.pl b/challenge-324/adam-russell/perl/ch-1.pl new file mode 100644 index 0000000000..3adee3b8e6 --- /dev/null +++ b/challenge-324/adam-russell/perl/ch-1.pl @@ -0,0 +1,49 @@ + + use v5.40; + + sub create_array{ + my($i, $r, $c) = @_; + my @a = (); + for (0 .. $r - 1){ + my $row = []; + for (0 .. $c - 1){ + push @{$row}, shift @{$i}; + } + push @a, $row; + } + return @a; + } + + +MAIN:{ + my $s = q//; + $s .= q/(/; + do{ + $s.= (q/[/ . join(q/, /, @{$_}) . q/], /); + } for create_array [1, 2, 3, 4], 2, 2; + chop $s; + chop $s; + $s .= q/)/; + say $s; + + $s = q//; + $s .= q/(/; + do{ + $s.= (q/[/ . join(q/, /, @{$_}) . q/], /); + } for create_array [1, 2, 3], 1, 3; + chop $s; + chop $s; + $s .= q/)/; + say $s; + + $s = q//; + $s .= q/(/; + do{ + $s.= (q/[/ . join(q/, /, @{$_}) . q/], /); + } for create_array [1, 2, 3, 4], 4, 1; + chop $s; + chop $s; + $s .= q/)/; + say $s; +} + diff --git a/challenge-324/adam-russell/perl/ch-2.pl b/challenge-324/adam-russell/perl/ch-2.pl new file mode 100644 index 0000000000..6f741983d8 --- /dev/null +++ b/challenge-324/adam-russell/perl/ch-2.pl @@ -0,0 +1,33 @@ + + use v5.40; + + sub power_set{ + my @a = (); + for my $i (1 .. 2 ** @_- 1){ + my @digits = (); + for my $j (0 .. @_ - 1){ + push @digits, $_[$j] if 1 == ($i >> $j & 1); + } + push @a, \@digits; + } + return @a; + } + + + sub calculate_total_xor{ + my $total = 0; + for my $a (power_set @_){ + my $t = 0; + $t = eval join q/ ^ /, ($t, @{$a}); + $total += $t; + } + return $total; + } + + +MAIN:{ + say calculate_total_xor 1, 3; + say calculate_total_xor 5, 1, 6; + say calculate_total_xor 3, 4, 5, 6, 7, 8; +} + |
