diff options
| -rwxr-xr-x | challenge-139/cristian-heredia/perl/ch_1.pl | 36 | ||||
| -rwxr-xr-x | challenge-139/cristian-heredia/python/ch_1.py | 30 |
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")
|
