aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAbigail <abigail@abigail.be>2021-03-29 19:55:12 +0200
committerAbigail <abigail@abigail.be>2021-03-29 19:55:12 +0200
commit03e6a6514dfd975f77883e56ca2e2dc0ed56ffa6 (patch)
tree062c164a76d1f54d065ef3df94e1baba67b20702
parent74674b61d0b644177f71423b92c3ca06e9c86fd3 (diff)
downloadperlweeklychallenge-club-03e6a6514dfd975f77883e56ca2e2dc0ed56ffa6.tar.gz
perlweeklychallenge-club-03e6a6514dfd975f77883e56ca2e2dc0ed56ffa6.tar.bz2
perlweeklychallenge-club-03e6a6514dfd975f77883e56ca2e2dc0ed56ffa6.zip
Python solution for week 106, part 1
-rw-r--r--challenge-106/abigail/README.md1
-rw-r--r--challenge-106/abigail/python/ch-1.py36
2 files changed, 37 insertions, 0 deletions
diff --git a/challenge-106/abigail/README.md b/challenge-106/abigail/README.md
index 136cddfcc3..c65ff505ce 100644
--- a/challenge-106/abigail/README.md
+++ b/challenge-106/abigail/README.md
@@ -27,6 +27,7 @@ Output: 0
* [Lua](lua/ch-1.lua)
* [Node.js](node/ch-1.js)
* [Perl](perl/ch-1.pl)
+* [Python](python/ch-1.py)
### Blog
[]()
diff --git a/challenge-106/abigail/python/ch-1.py b/challenge-106/abigail/python/ch-1.py
new file mode 100644
index 0000000000..dbade40e72
--- /dev/null
+++ b/challenge-106/abigail/python/ch-1.py
@@ -0,0 +1,36 @@
+#!/opt/local/bin/python
+
+#
+# See ../README.md
+#
+
+#
+# Run as: python ch-1.py < input-file
+#
+
+import fileinput
+
+for line in fileinput . input ():
+ #
+ # Extract the numbers from the line of input, by splitting
+ # the input on white space, and forcing the chucks to be integer.
+ #
+ N = list (map (lambda x: int (x), line . split ()))
+
+ #
+ # sort () modifies the array
+ #
+ N . sort ()
+
+ #
+ # Find the maximum difference
+ #
+ max = 0
+ for i in range (1, len (N)):
+ if N [i] - N [i - 1] > max:
+ max = N [i] - N [i - 1]
+
+ #
+ # Print it
+ #
+ print (max)