diff options
| -rwxr-xr-x | challenge-078/e-choroba/perl/ch-1.pl | 25 | ||||
| -rwxr-xr-x | challenge-078/e-choroba/perl/ch-2.pl | 22 |
2 files changed, 47 insertions, 0 deletions
diff --git a/challenge-078/e-choroba/perl/ch-1.pl b/challenge-078/e-choroba/perl/ch-1.pl new file mode 100755 index 0000000000..ba8aac506b --- /dev/null +++ b/challenge-078/e-choroba/perl/ch-1.pl @@ -0,0 +1,25 @@ +#!/usr/bin/perl +use warnings; +use strict; + +sub leader_element { + my ($list) = @_; + return [] unless @$list; + + my @leaders = $list->[-1]; + for my $n (reverse @$list) { + unshift @leaders, $n if $n > $leaders[0]; + } + + return \@leaders +} + +use Test::More tests => 2; + +is_deeply leader_element([9, 10, 7, 5, 6, 1]), + [10, 7, 6, 1], + 'example 1'; + +is_deeply leader_element([3, 4, 5]), + [5], + 'example 2'; diff --git a/challenge-078/e-choroba/perl/ch-2.pl b/challenge-078/e-choroba/perl/ch-2.pl new file mode 100755 index 0000000000..606e94c2a6 --- /dev/null +++ b/challenge-078/e-choroba/perl/ch-2.pl @@ -0,0 +1,22 @@ +#!/usr/bin/perl +use warnings; +use strict; + +sub left_rotation { + my ($list, $rotations) = @_; + return [ map { + [ @$list[$_ .. $#$list], @$list[0 .. $_ - 1] ] + } @$rotations ] +} + +use Test::More tests => 2; + +is_deeply left_rotation([10, 20, 30, 40, 50], [3, 4]), + [ [40, 50, 10, 20, 30], + [50, 10, 20, 30, 40] ]; + +is_deeply left_rotation([ 7, 4, 2, 6, 3 ], [1, 3, 4]), + [ [ 4, 2, 6, 3, 7 ], + [ 6, 3, 7, 4, 2 ], + [ 3, 7, 4, 2, 6 ] ]; + |
