diff options
| -rwxr-xr-x | challenge-206/matthias-muth/perl/ch-1.pl | 2 | ||||
| -rwxr-xr-x | challenge-206/matthias-muth/perl/ch-2.pl | 9 |
2 files changed, 6 insertions, 5 deletions
diff --git a/challenge-206/matthias-muth/perl/ch-1.pl b/challenge-206/matthias-muth/perl/ch-1.pl index a23923ea9f..5553b96208 100755 --- a/challenge-206/matthias-muth/perl/ch-1.pl +++ b/challenge-206/matthias-muth/perl/ch-1.pl @@ -8,7 +8,7 @@ no warnings 'experimental::signatures'; use List::Util qw( min ); sub time_diffs( $fixed, @others ) { - # Return all differences between one fixed timestamp and a list of others. + # Return all differences between one timestamp and a list of others. # Use the time difference spanning over midnight if it is shorter # (by simply using the minimum of both). return diff --git a/challenge-206/matthias-muth/perl/ch-2.pl b/challenge-206/matthias-muth/perl/ch-2.pl index 76758886f5..80dc03e7c0 100755 --- a/challenge-206/matthias-muth/perl/ch-2.pl +++ b/challenge-206/matthias-muth/perl/ch-2.pl @@ -6,8 +6,6 @@ use warnings; use feature 'signatures'; no warnings 'experimental::signatures'; -use List::Util qw( min max sum ); - sub permute( $a_ref ) { return undef unless defined $a_ref && ref $a_ref eq 'ARRAY'; return () if @$a_ref == 0; @@ -23,11 +21,14 @@ sub permute( $a_ref ) { return @permutations; } +use List::Util qw( min max sum ); + sub sum_of_min_of_pairs( @a ) { return undef unless @a % 2 == 0; - return - sum( map $_ % 2 == 0 ? min( $a[$_], $a[ $_ + 1 ] ) : 0, 0 .. $#a - 1 ); + return sum( + map $_ % 2 == 0 ? min( $a[$_], $a[ $_ + 1 ] ) : 0, 0..( $#a - 1 ) + ); } sub max_of_sums( @a ) { |
