diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2023-03-06 01:58:37 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-03-06 01:58:37 +0000 |
| commit | 41a06fcc3be0579a6d272a0168d50e0b1e5254ce (patch) | |
| tree | b131e71d16328bbc60830f6338598c73cfb2d0f1 | |
| parent | 23632a35cd0898831f905d6cff4c0934cabc57a9 (diff) | |
| parent | 6b534c0c496bc67578949ce86f332d7f67dba540 (diff) | |
| download | perlweeklychallenge-club-41a06fcc3be0579a6d272a0168d50e0b1e5254ce.tar.gz perlweeklychallenge-club-41a06fcc3be0579a6d272a0168d50e0b1e5254ce.tar.bz2 perlweeklychallenge-club-41a06fcc3be0579a6d272a0168d50e0b1e5254ce.zip | |
Merge pull request #7671 from Solathian/branch-for-challenge-206
added file for challenge 206
| -rw-r--r-- | challenge-206/solathian/perl/ch-1.pl | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/challenge-206/solathian/perl/ch-1.pl b/challenge-206/solathian/perl/ch-1.pl new file mode 100644 index 0000000000..c7d616c0b3 --- /dev/null +++ b/challenge-206/solathian/perl/ch-1.pl @@ -0,0 +1,39 @@ +#!usr/bin/perl +use v5.36; + +# Challenge 206 - 1 - Shortest Time +# You are given a list of time points, at least 2, in the 24-hour clock format HH:MM. +# Write a script to find out the shortest time in minutes between any two time points. + + +shortTime("00:00", "23:55", "20:00"); +shortTime("01:01", "00:50", "00:57"); +shortTime("10:10", "09:30", "09:00", "09:55"); + +sub shortTime(@array) +{ + foreach my $time (@array) + { + my ($hour, $minutes) = $time =~ m"(\d\d):(\d\d)"; + $time = $hour*60 + $minutes; + } + + my $shortTime = 1440; + + foreach my $time (@array) + { + foreach my $secondTime (@array) + { + next if($time == $secondTime); + + my $tempTime = $secondTime; + + ($tempTime += 1440) if($time > $secondTime); + + $shortTime = ($tempTime - $time) if(($tempTime - $time) < $shortTime ); + } + + } + + say $shortTime; +}
\ No newline at end of file |
