aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2021-11-16 20:06:59 +0000
committerGitHub <noreply@github.com>2021-11-16 20:06:59 +0000
commitd5b0dae69d35b346a0f3f574830be307e496e7e8 (patch)
treea815e72b80d09dc4d08ef33d0c822ee1eb4a5d31
parente6e1b5c57057cde7211e289fe35ec9805f750c69 (diff)
parent8c97674d4297af94c60cacbe54f65899fc3d5660 (diff)
downloadperlweeklychallenge-club-d5b0dae69d35b346a0f3f574830be307e496e7e8.tar.gz
perlweeklychallenge-club-d5b0dae69d35b346a0f3f574830be307e496e7e8.tar.bz2
perlweeklychallenge-club-d5b0dae69d35b346a0f3f574830be307e496e7e8.zip
Merge pull request #5235 from Cris-HD/branch-for-challenge-139
Added challenge 139 solution
-rwxr-xr-xchallenge-139/cristian-heredia/perl/ch_1.pl36
-rwxr-xr-xchallenge-139/cristian-heredia/python/ch_1.py30
2 files changed, 66 insertions, 0 deletions
diff --git a/challenge-139/cristian-heredia/perl/ch_1.pl b/challenge-139/cristian-heredia/perl/ch_1.pl
new file mode 100755
index 0000000000..1dc552d481
--- /dev/null
+++ b/challenge-139/cristian-heredia/perl/ch_1.pl
@@ -0,0 +1,36 @@
+=begin
+
+ TASK #1 › JortSort
+ Submitted by: Mohammad S Anwar
+ You are given a list of numbers.
+
+ Write a script to implement JortSort. It should return true/false depending if the given list of numbers are already sorted.
+
+ Example 1:
+ Input: @n = (1,2,3,4,5)
+ Output: 1
+
+ Since the array is sorted, it prints 1.
+ Example 2:
+ Input: @n = (1,3,2,4,5)
+ Output: 0
+
+ Since the array is NOT sorted, it prints 0.
+=end
+=cut
+
+use strict;
+use warnings;
+
+# Input
+my @n = (1,2,3,4,5);
+
+my @sortN = sort { $a <=> $b } @n;
+
+for (my $i =0; $i<@n;$i++){
+ if ($n[$i]!= $sortN[$i]){
+ print("0\n");
+ exit;
+ }
+}
+print("1\n"); \ No newline at end of file
diff --git a/challenge-139/cristian-heredia/python/ch_1.py b/challenge-139/cristian-heredia/python/ch_1.py
new file mode 100755
index 0000000000..dda860e901
--- /dev/null
+++ b/challenge-139/cristian-heredia/python/ch_1.py
@@ -0,0 +1,30 @@
+"""
+
+ TASK #1 › JortSort
+ Submitted by: Mohammad S Anwar
+ You are given a list of numbers.
+
+ Write a script to implement JortSort. It should return true/false depending if the given list of numbers are already sorted.
+
+ Example 1:
+ Input: @n = (1,2,3,4,5)
+ Output: 1
+
+ Since the array is sorted, it prints 1.
+ Example 2:
+ Input: @n = (1,3,2,4,5)
+ Output: 0
+
+ Since the array is NOT sorted, it prints 0.
+
+"""
+
+# Input
+n = (1, 2, 3, 4, 5)
+
+sortN = sorted(n)
+for i in range(len(n)):
+ if n[i] != sortN[i]:
+ print("0")
+ exit()
+print("1")