From 4fbb9e3cddc115b656a62b60ad992c44998d0bf7 Mon Sep 17 00:00:00 2001 From: Matthew Neleigh Date: Mon, 17 Nov 2025 15:55:54 -0500 Subject: modified: challenge-348/mattneleigh/perl/ch-2.pl --- challenge-348/mattneleigh/perl/ch-2.pl | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/challenge-348/mattneleigh/perl/ch-2.pl b/challenge-348/mattneleigh/perl/ch-2.pl index 46516f7188..56a3e4098d 100755 --- a/challenge-348/mattneleigh/perl/ch-2.pl +++ b/challenge-348/mattneleigh/perl/ch-2.pl @@ -56,15 +56,19 @@ sub ops_to_make_time_difference{ $start = [ split(/:/, $start) ]; $end = [ split(/:/, $end) ]; - # If the hour of the end time appears to be less - # than that of the start time, assume that it's - # from the next day - $end->[0] += 24 - if($end->[0] < $start->[0]); - - # Convert hours and minutes to just minutes, and - # calculate the difference - $diff = ($end->[0] * 60 + $end->[1]) - ($start->[0] * 60 + $start->[1]); + # Convert the times into numbers of minutes since + # 00:00 + $end = ($end->[0] * 60 + $end->[1]); + $start = ($start->[0] * 60 + $start->[1]); + + # If the end appears to be before the start, + # assume that it's meant to be the next day + $end += 1440 + if($end < $start); + + # Calculate the difference between the start and + # end times + $diff = $end - $start; # Loop over each unit of minutes, determining how # many of each are required to equal the difference -- cgit