diff options
| -rw-r--r-- | challenge-100/lubos-kolouch/perl/ch-2.pl | 6 | ||||
| -rw-r--r-- | challenge-100/lubos-kolouch/python/ch-1.py | 31 | ||||
| -rw-r--r-- | challenge-100/lubos-kolouch/python/ch-2.py | 57 |
3 files changed, 91 insertions, 3 deletions
diff --git a/challenge-100/lubos-kolouch/perl/ch-2.pl b/challenge-100/lubos-kolouch/perl/ch-2.pl index e9bc3df9ed..778d0723b4 100644 --- a/challenge-100/lubos-kolouch/perl/ch-2.pl +++ b/challenge-100/lubos-kolouch/perl/ch-2.pl @@ -16,7 +16,7 @@ use strict; use warnings; -sub min_sum { +sub min_sums { my $what = shift; # @@ -54,7 +54,7 @@ sub min_sum { } 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 ); +is( min_sums( [ [1], [ 2, 4 ], [ 6, 4, 9 ], [ 5, 1, 7, 2 ] ] ), 8 ); +is( min_sums( [ [3], [3,1], [5,2,3], [4,3,1,3] ] ), 7 ); done_testing; diff --git a/challenge-100/lubos-kolouch/python/ch-1.py b/challenge-100/lubos-kolouch/python/ch-1.py new file mode 100644 index 0000000000..5c5eee47d8 --- /dev/null +++ b/challenge-100/lubos-kolouch/python/ch-1.py @@ -0,0 +1,31 @@ +#!/usr/bin/python +""" +#=============================================================================== +# +# FILE: ch-1.py +# +# USAGE: ./ch-1.py +# +# DESCRIPTION: Perl Weekly Challenge #100 +# Task 1 +# AUTHOR: Lubos Kolouch +# CREATED: 02/20/2021 10:16:51 AM +#=============================================================================== +""" +from time import strptime, strftime + + +def convert_time(inp_time): + """ Convert the time as required """ + + new_time = inp_time.replace(" ", "") + parse_pattern = '%H:%M' if 'm' not in inp_time else '%I:%M%p' + out_pattern = '%H:%M' if 'm' in inp_time else '%I:%M%p' + + conv_time = strptime(new_time, parse_pattern) + return strftime(out_pattern, conv_time) + + +assert convert_time('05:15pm') == '17:15' +assert convert_time('05:15 pm') == '17:15' +assert convert_time('19:15') == '07:15PM' diff --git a/challenge-100/lubos-kolouch/python/ch-2.py b/challenge-100/lubos-kolouch/python/ch-2.py new file mode 100644 index 0000000000..2c25aa2998 --- /dev/null +++ b/challenge-100/lubos-kolouch/python/ch-2.py @@ -0,0 +1,57 @@ +#!/usr/bin/python +""" +#=============================================================================== +# +# FILE: ch_2.py +# +# USAGE: ./ch_2.py +# +# 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 +#=============================================================================== +""" + + +def min_sums(what): + """ Get the min sum as requested """ + + # + # 1 + # |\ + # 2 4 + # |\|\ + # 6 4 9 + # |\|\|\ + # 5 1 7 2 + + row_counter = 0 + min_path = None + sums = {} + for row in what: + row_counter += 1 + col_counter = 0 + for item in row: + col_counter += 1 + + min_sum = sums.get((row_counter-1, col_counter), None) + if sums.get((row_counter-1, col_counter-1), None): + if (not min_sum or sums[(row_counter-1, col_counter-1)] < min_sum): + min_sum = sums[(row_counter-1, col_counter-1)] + + if not min_sum: + min_sum = 0 + + sums[(row_counter, col_counter)] = item + min_sum + + if row_counter == len(what): + if (not min_path) or (item + min_sum < min_path): + min_path = item + min_sum + return min_path + + +assert min_sums([[1], [2, 4], [6, 4, 9], [5, 1, 7, 2]]) == 8 +assert min_sums([[3], [3, 1], [5, 2, 3], [4, 3, 1, 3]]) == 7 |
