diff options
| author | E. Choroba <choroba@matfyz.cz> | 2024-05-13 09:48:08 +0200 |
|---|---|---|
| committer | E. Choroba <choroba@matfyz.cz> | 2024-05-13 09:48:08 +0200 |
| commit | 264298ed145e2c29e95184e62ca873b7cb355501 (patch) | |
| tree | b1179489dd99ac006681ef256b3c6b5e26dbd1e6 /challenge-269 | |
| parent | 02e309b3d451fff60404eb5ab3e539056f99ce0d (diff) | |
| download | perlweeklychallenge-club-264298ed145e2c29e95184e62ca873b7cb355501.tar.gz perlweeklychallenge-club-264298ed145e2c29e95184e62ca873b7cb355501.tar.bz2 perlweeklychallenge-club-264298ed145e2c29e95184e62ca873b7cb355501.zip | |
Add solutions to 269: Bitwise OR & Distribute Elements by E. Choroba
Diffstat (limited to 'challenge-269')
| -rwxr-xr-x | challenge-269/e-choroba/perl/ch-1.pl | 14 | ||||
| -rwxr-xr-x | challenge-269/e-choroba/perl/ch-2.pl | 20 |
2 files changed, 34 insertions, 0 deletions
diff --git a/challenge-269/e-choroba/perl/ch-1.pl b/challenge-269/e-choroba/perl/ch-1.pl new file mode 100755 index 0000000000..88936a0b4f --- /dev/null +++ b/challenge-269/e-choroba/perl/ch-1.pl @@ -0,0 +1,14 @@ +#!/usr/bin/perl +use warnings; +use strict; +use experimental qw( signatures ); + +sub bitwise_or(@ints) { + return 1 < grep 0 == $_ % 2, @ints +} + +use Test::More tests => 3; + +ok bitwise_or(1, 2, 3, 4, 5), 'Example 1'; +ok bitwise_or(2, 3, 8, 16), 'Example 2'; +ok ! bitwise_or(1, 2, 5, 7, 9), 'Example 3'; diff --git a/challenge-269/e-choroba/perl/ch-2.pl b/challenge-269/e-choroba/perl/ch-2.pl new file mode 100755 index 0000000000..d2d32147ba --- /dev/null +++ b/challenge-269/e-choroba/perl/ch-2.pl @@ -0,0 +1,20 @@ +#!/usr/bin/perl +use warnings; +use strict; +use experimental qw( signatures ); + +sub distribute_elements(@ints) { + my @arr1 = shift @ints; + my @arr2 = shift @ints; + while (@ints) { + push @{ $arr1[-1] > $arr2[-1] ? \@arr1 : \@arr2 }, shift @ints; + } + return @arr1, @arr2 +} + +use Test2::V0; +plan(3); + +is [distribute_elements(2, 1, 3, 4, 5)], [2, 3, 4, 5, 1], 'Example 1'; +is [distribute_elements(3, 2, 4)], [3, 4, 2], 'Example 2'; +is [distribute_elements(5, 4, 3 ,8)], [5, 3, 4, 8], 'Example 3'; |
