aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCris-HD <crisn7@hotmail.com>2021-04-04 17:11:54 +0200
committerCris-HD <crisn7@hotmail.com>2021-04-04 17:11:54 +0200
commit409c876edf5a631c5a748cdc09bfc7f09b9c5ace (patch)
tree650341978e9b3da28848931b978570ea935572af
parentd5ff10db3ea3e9e6e150316af0d4e4c0e2a37fe1 (diff)
downloadperlweeklychallenge-club-409c876edf5a631c5a748cdc09bfc7f09b9c5ace.tar.gz
perlweeklychallenge-club-409c876edf5a631c5a748cdc09bfc7f09b9c5ace.tar.bz2
perlweeklychallenge-club-409c876edf5a631c5a748cdc09bfc7f09b9c5ace.zip
Added challenge 106 solution
-rw-r--r--challenge-106/cristian-heredia/perl/ch_1.pl53
-rw-r--r--challenge-106/cristian-heredia/python/ch_1.py48
2 files changed, 101 insertions, 0 deletions
diff --git a/challenge-106/cristian-heredia/perl/ch_1.pl b/challenge-106/cristian-heredia/perl/ch_1.pl
new file mode 100644
index 0000000000..d27b24e3ab
--- /dev/null
+++ b/challenge-106/cristian-heredia/perl/ch_1.pl
@@ -0,0 +1,53 @@
+=begin
+
+ 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
+
+=end
+=cut
+
+
+use strict;
+use warnings;
+use Data::Dumper;
+
+
+#Input
+my @N = (2, 9, 3, 5);
+
+my $result = 0;
+my $sub = 0;
+
+if (@N != 1) {
+ my @sorted = sort { $a <=> $b } @N;
+ for (my $i= 0; $i<@N-1; $i++) {
+ $sub = $sorted[$i+1] - $sorted[$i];
+ if ($sub > $result) {
+ $result = $sub;
+ }
+ }
+}
+print "$result\n";
+
+
+
+
+
+
+
+
diff --git a/challenge-106/cristian-heredia/python/ch_1.py b/challenge-106/cristian-heredia/python/ch_1.py
new file mode 100644
index 0000000000..0bdb1efffb
--- /dev/null
+++ b/challenge-106/cristian-heredia/python/ch_1.py
@@ -0,0 +1,48 @@
+'''
+
+ 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
+
+'''
+
+
+#Input
+N = [2, 9, 3, 5]
+
+result = 0
+subs = 0
+counter = 0
+
+
+if (len(N) != 1):
+ sortedList = sorted(N)
+ while (counter < len(N)-1):
+ subs = sortedList[counter+1] - sortedList[counter]
+ if (subs > result):
+ result = subs;
+ counter += 1
+
+print (result);
+
+
+
+
+
+
+
+