diff options
| -rwxr-xr-x | challenge-321/e-choroba/perl/ch-1.pl | 17 | ||||
| -rwxr-xr-x | challenge-321/e-choroba/perl/ch-2.pl | 18 |
2 files changed, 35 insertions, 0 deletions
diff --git a/challenge-321/e-choroba/perl/ch-1.pl b/challenge-321/e-choroba/perl/ch-1.pl new file mode 100755 index 0000000000..6cbf0aa7da --- /dev/null +++ b/challenge-321/e-choroba/perl/ch-1.pl @@ -0,0 +1,17 @@ +#!/usr/bin/perl +use warnings; +use strict; +use experimental qw( signatures ); + +sub distinct_average(@nums) { + @nums = sort { $a <=> $b } @nums; + my %avg; + undef $avg{ ($nums[$_] + $nums[ $#nums - $_ ]) / 2 } for 0 .. @nums / 2; + return scalar keys %avg +} + +use Test::More tests => 3; + +is distinct_average(1, 2, 4, 3, 5, 6), 1, 'Example 1'; +is distinct_average(0, 2, 4, 8, 3, 5), 2, 'Example 2'; +is distinct_average(7, 3, 1, 0, 5, 9), 2, 'Example 3'; diff --git a/challenge-321/e-choroba/perl/ch-2.pl b/challenge-321/e-choroba/perl/ch-2.pl new file mode 100755 index 0000000000..a1603b42c7 --- /dev/null +++ b/challenge-321/e-choroba/perl/ch-2.pl @@ -0,0 +1,18 @@ +#!/usr/bin/perl +use warnings; +use strict; +use experimental qw( signatures ); + +sub backspace_compare($str1, $str2) { + for ($str1, $str2) { + 1 while s/[^#]#//; + } + return $str1 eq $str2 +} + +use Test2::V0; +plan(3); + +is backspace_compare('ab#c', 'ad#c'), bool(1), 'Example 1'; +is backspace_compare('ab##', 'a#b#'), bool(1), 'Example 2'; +is backspace_compare('a#b', 'c'), bool(0), 'Example 3'; |
