aboutsummaryrefslogtreecommitdiff
path: root/challenge-106
diff options
context:
space:
mode:
authorPaulo Custodio <pauloscustodio@gmail.com>2021-11-05 17:08:25 +0000
committerPaulo Custodio <pauloscustodio@gmail.com>2021-11-05 17:08:25 +0000
commit22e45b2c865e5dc510215516bf12ea85f9691ae8 (patch)
tree0416ce13b7750637d3638d3599315675b669cb14 /challenge-106
parentc332a12738c06cd4dcf92702e86ce69c2e826bd7 (diff)
downloadperlweeklychallenge-club-22e45b2c865e5dc510215516bf12ea85f9691ae8.tar.gz
perlweeklychallenge-club-22e45b2c865e5dc510215516bf12ea85f9691ae8.tar.bz2
perlweeklychallenge-club-22e45b2c865e5dc510215516bf12ea85f9691ae8.zip
Add Python solution to challenge 106 task 1
Diffstat (limited to 'challenge-106')
-rw-r--r--challenge-106/paulo-custodio/Makefile2
-rw-r--r--challenge-106/paulo-custodio/perl/ch-1.pl2
-rw-r--r--challenge-106/paulo-custodio/python/ch-1.py38
-rw-r--r--challenge-106/paulo-custodio/test.pl4
4 files changed, 41 insertions, 5 deletions
diff --git a/challenge-106/paulo-custodio/Makefile b/challenge-106/paulo-custodio/Makefile
new file mode 100644
index 0000000000..c3c762d746
--- /dev/null
+++ b/challenge-106/paulo-custodio/Makefile
@@ -0,0 +1,2 @@
+all:
+ perl ../../challenge-001/paulo-custodio/test.pl
diff --git a/challenge-106/paulo-custodio/perl/ch-1.pl b/challenge-106/paulo-custodio/perl/ch-1.pl
index 90324d33ea..13c5bc7bb6 100644
--- a/challenge-106/paulo-custodio/perl/ch-1.pl
+++ b/challenge-106/paulo-custodio/perl/ch-1.pl
@@ -1,4 +1,4 @@
-#!/usr/bin/perl
+#!/usr/bin/env perl
# Challenge 106
#
diff --git a/challenge-106/paulo-custodio/python/ch-1.py b/challenge-106/paulo-custodio/python/ch-1.py
new file mode 100644
index 0000000000..f97fce6cf0
--- /dev/null
+++ b/challenge-106/paulo-custodio/python/ch-1.py
@@ -0,0 +1,38 @@
+#!/usr/bin/env python3
+
+# Challenge 106
+#
+# TASK #1 > Maximum Gap
+# Submitted by: Mohammad S Anwar
+# You are given an array of integers @N.
+#
+# Write a script to display the maximum difference between two successive
+# elements once the array is sorted.
+#
+# If the array contains only 1 element then display 0.
+#
+# Example
+# Input: @N = (2, 9, 3, 5)
+# Output: 4
+#
+# Input: @N = (1, 3, 8, 2, 0)
+# Output: 5
+#
+# Input: @N = (5)
+# Output: 0
+
+import sys
+
+def max_gap(n):
+ if len(n)<2:
+ return 0
+ n.sort()
+
+ max_gap = 0
+ for i in range(0, len(n)-1):
+ gap = n[i+1]-n[i]
+ max_gap = max(max_gap, gap)
+
+ return max_gap
+
+print(max_gap([int(x) for x in sys.argv[1:]]))
diff --git a/challenge-106/paulo-custodio/test.pl b/challenge-106/paulo-custodio/test.pl
deleted file mode 100644
index ba6c37260b..0000000000
--- a/challenge-106/paulo-custodio/test.pl
+++ /dev/null
@@ -1,4 +0,0 @@
-#!/usr/bin/env perl
-use Modern::Perl;
-use Test::More;
-require '../../challenge-001/paulo-custodio/test.pl';