aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Mahnke <andreas.mahnke@leuphana.de>2025-11-17 10:49:02 +0100
committerAndreas Mahnke <andreas.mahnke@leuphana.de>2025-11-17 10:49:02 +0100
commit553b1e992d5cdd7503abc27ce4503c9ac2b76c37 (patch)
tree27ccdf3f2eea45f430805f19c34f56ccbd1d81b9
parent0c4253f2935f404a0e195ac171bf4f5487301e16 (diff)
downloadperlweeklychallenge-club-553b1e992d5cdd7503abc27ce4503c9ac2b76c37.tar.gz
perlweeklychallenge-club-553b1e992d5cdd7503abc27ce4503c9ac2b76c37.tar.bz2
perlweeklychallenge-club-553b1e992d5cdd7503abc27ce4503c9ac2b76c37.zip
fixed ch-2, added hour overflow
-rw-r--r--challenge-348/mahnkong/perl/ch-2.pl10
1 files changed, 7 insertions, 3 deletions
diff --git a/challenge-348/mahnkong/perl/ch-2.pl b/challenge-348/mahnkong/perl/ch-2.pl
index 42edda969d..fbb1af92ff 100644
--- a/challenge-348/mahnkong/perl/ch-2.pl
+++ b/challenge-348/mahnkong/perl/ch-2.pl
@@ -5,9 +5,9 @@ use Test::More 'no_plan';
my @operations = (1, 5, 15, 60);
-sub get_minutes($str, $is_target = 0) {
+sub get_minutes($str) {
my @parts = split /:/, $str;
- if ($is_target && $parts[0] eq "00") {
+ if ($parts[0] eq "00") {
$parts[0] = "24";
}
my $m = $parts[0]*60 + $parts[1];
@@ -15,7 +15,10 @@ sub get_minutes($str, $is_target = 0) {
}
sub run($source, $target) {
- my $diff = get_minutes($target, 1) - get_minutes($source);
+ my $diff = get_minutes($target) - get_minutes($source);
+ if ($diff < 0) {
+ $diff = 1440 - abs($diff);
+ }
my $operations = 0;
while ($diff > 0) {
foreach my $o (reverse(@operations)) {
@@ -34,3 +37,4 @@ is(run("11:55", "12:15"), 2, "Example 2");
is(run("09:00", "13:00"), 4, "Example 3");
is(run("23:45", "00:30"), 3, "Example 4");
is(run("14:20", "15:25"), 2, "Example 5");
+is(run("22:20", "04:20"), 6, "Example 6");