aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-128/abigail/README.md1
-rw-r--r--challenge-128/abigail/python/ch-2.py37
2 files changed, 38 insertions, 0 deletions
diff --git a/challenge-128/abigail/README.md b/challenge-128/abigail/README.md
index 72a59e6317..b4279b09ff 100644
--- a/challenge-128/abigail/README.md
+++ b/challenge-128/abigail/README.md
@@ -70,6 +70,7 @@ station, so we need minimum 3 platforms.
* [Lua](lua/ch-2.lua)
* [Node.js](node/ch-2.js)
* [Perl](perl/ch-2.pl)
+* [Python](python/ch-2.py)
### Blog
[Perl Weekly Challenge 128: Minimum Platforms][blog2]
diff --git a/challenge-128/abigail/python/ch-2.py b/challenge-128/abigail/python/ch-2.py
new file mode 100644
index 0000000000..85cb8df8e6
--- /dev/null
+++ b/challenge-128/abigail/python/ch-2.py
@@ -0,0 +1,37 @@
+#!/opt/local/bin/python
+
+#
+# See ../README.md
+#
+
+#
+# Run as: python ch-1.py < input-file
+#
+
+import re
+
+def get_time (time):
+ hours, minutes = map (lambda x: int (x), time . split (":"))
+ return (60 * hours + minutes)
+
+def read_times ():
+ return (list (map (get_time,
+ re . findall (r'[0-9][0-9]:[0-9][0-9]', input ()))))
+
+arrivals = read_times ()
+departures = read_times ()
+
+trains = [0] * (24 * 60)
+
+for i in range (len (arrivals)):
+ arrival = arrivals [i]
+ departure = departures [i]
+ for i in range (arrival, departure + 1):
+ trains [i] = trains [i] + 1
+ if departure < arrival:
+ for i in range (0, departure + 1):
+ trains [i] = trains [i] + 1
+ for i in range (arrival, 24 * 60):
+ trains [i] = trains [i] + 1
+
+print (max (trains))