aboutsummaryrefslogtreecommitdiff
path: root/challenge-206/lubos-kolouch/python/ch-1.py
diff options
context:
space:
mode:
authorLubos Kolouch <lubos@kolouch.net>2023-02-28 18:39:31 +0100
committerLubos Kolouch <lubos@kolouch.net>2023-02-28 18:39:31 +0100
commitfde49e5cd629f30578b4b6fdc7ddc0dadfc39345 (patch)
tree45ab4aa753a8d6488d4c116f387566a48e43956c /challenge-206/lubos-kolouch/python/ch-1.py
parent09eef326c170759598ee2d5d35a5aad50be4a11c (diff)
downloadperlweeklychallenge-club-fde49e5cd629f30578b4b6fdc7ddc0dadfc39345.tar.gz
perlweeklychallenge-club-fde49e5cd629f30578b4b6fdc7ddc0dadfc39345.tar.bz2
perlweeklychallenge-club-fde49e5cd629f30578b4b6fdc7ddc0dadfc39345.zip
Challenge 206 LK Perl Python Bash Java PHP
Diffstat (limited to 'challenge-206/lubos-kolouch/python/ch-1.py')
-rw-r--r--challenge-206/lubos-kolouch/python/ch-1.py35
1 files changed, 35 insertions, 0 deletions
diff --git a/challenge-206/lubos-kolouch/python/ch-1.py b/challenge-206/lubos-kolouch/python/ch-1.py
new file mode 100644
index 0000000000..ac6bd1129b
--- /dev/null
+++ b/challenge-206/lubos-kolouch/python/ch-1.py
@@ -0,0 +1,35 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+import unittest
+
+
+def shortest_time_in_minutes(*times):
+ min_diff = 24 * 60 # maximum possible difference in minutes
+ for i in range(len(times) - 1):
+ for j in range(i + 1, len(times)):
+ h1, m1 = map(int, times[i].split(':'))
+ h2, m2 = map(int, times[j].split(':'))
+ diff = abs((h1 - h2) * 60 + (m1 - m2))
+ diff = 24 * 60 - diff if diff > 12 * 60 else diff # account for circular time
+ min_diff = min(diff, min_diff)
+ return min_diff
+
+
+class TestShortestTimeInMinutes(unittest.TestCase):
+
+ def test_example1(self):
+ self.assertEqual(shortest_time_in_minutes("00:00", "23:55", "20:00"),
+ 5)
+
+ def test_example2(self):
+ self.assertEqual(shortest_time_in_minutes("01:01", "00:50", "00:57"),
+ 4)
+
+ def test_example3(self):
+ self.assertEqual(
+ shortest_time_in_minutes("10:10", "09:30", "09:00", "09:55"), 15)
+
+
+if __name__ == '__main__':
+ unittest.main()