diff options
| -rw-r--r-- | challenge-100/lubos-kolouch/perl/ch-1.pl | 35 | ||||
| -rw-r--r-- | challenge-100/lubos-kolouch/perl/ch-2.pl | 60 |
2 files changed, 95 insertions, 0 deletions
diff --git a/challenge-100/lubos-kolouch/perl/ch-1.pl b/challenge-100/lubos-kolouch/perl/ch-1.pl new file mode 100644 index 0000000000..06b2962ba7 --- /dev/null +++ b/challenge-100/lubos-kolouch/perl/ch-1.pl @@ -0,0 +1,35 @@ +#!/usr/bin/perl +#=============================================================================== +# +# FILE: ch-1.pl +# +# USAGE: ./ch-1.pl +# +# DESCRIPTION: Perl Weekly Challenge #100 +# Task 1 +# AUTHOR: Lubos Kolouch +# CREATED: 02/20/2021 10:16:51 AM +#=============================================================================== + +use strict; +use warnings; +use DateTime::Format::DateParse; + +sub convert_time { + my $what = shift; + + my $pattern = $what =~ /m/ ? '%H:%M' : '%I:%M %P'; + + return DateTime::Format::DateParse + -> parse_datetime($what) + -> strftime($pattern); + +} + +use Test::More; + +is(convert_time('05:15pm'), '17:15'); +is(convert_time('05:15 pm'), '17:15'); +is(convert_time('19:15'), '07:15 pm'); + +done_testing; diff --git a/challenge-100/lubos-kolouch/perl/ch-2.pl b/challenge-100/lubos-kolouch/perl/ch-2.pl new file mode 100644 index 0000000000..e9bc3df9ed --- /dev/null +++ b/challenge-100/lubos-kolouch/perl/ch-2.pl @@ -0,0 +1,60 @@ +#!/usr/bin/perl +#=============================================================================== +# +# FILE: ch_2.pl +# +# USAGE: ./ch_2.pl +# +# DESCRIPTION: Perl Weekly Challenge #100 +# https://perlweeklychallenge.org/blog/perl-weekly-challenge-100/ +# Triangle Sum +# +# AUTHOR: Lubos Kolouch +# CREATED: 2/20/2021 02:39:16 PM +#=============================================================================== + +use strict; +use warnings; + +sub min_sum { + my $what = shift; + + # + # 1 + # |\ + # 2 4 + # |\|\ + # 6 4 9 + # |\|\|\ + # 5 1 7 2 + + my $row_counter = 0; + my $min_path; + my %sums; + for my $row (@$what) { + $row_counter++; + my $col_counter = 0; + for my $item (@$row) { + $col_counter++; + my $min_sum; + + $min_sum = $sums{$row_counter-1, $col_counter} if exists($sums{$row_counter-1,$col_counter}); + $min_sum = $sums{$row_counter-1, $col_counter-1} if exists($sums{$row_counter-1,$col_counter-1}) and ( (not $min_sum) or ($sums{$row_counter-1,$col_counter-1} < $min_sum) ); + $min_sum //= 0; + + $sums{$row_counter,$col_counter} = $item + $min_sum; + + if ($row_counter == scalar @$what) { + $min_path = $item + $min_sum if ( (not $min_path) or ($item + $min_sum < $min_path)); + } + } + } + + return $min_path; +} +use Test::More; + +is( min_sum( [ [1], [ 2, 4 ], [ 6, 4, 9 ], [ 5, 1, 7, 2 ] ] ), 8 ); +is( min_sum( [ [3], [3,1], [5,2,3], [4,3,1,3] ] ), 7 ); + +done_testing; |
