diff options
| author | Cris-HD <crisn7@hotmail.com> | 2021-11-16 18:06:30 +0100 |
|---|---|---|
| committer | Cris-HD <crisn7@hotmail.com> | 2021-11-16 18:06:30 +0100 |
| commit | 8c97674d4297af94c60cacbe54f65899fc3d5660 (patch) | |
| tree | a875d3e40557168470c48b17601a9f78f461c23b | |
| parent | 428cb0b994d11282ea160574b67e4dbefd3eabbd (diff) | |
| download | perlweeklychallenge-club-8c97674d4297af94c60cacbe54f65899fc3d5660.tar.gz perlweeklychallenge-club-8c97674d4297af94c60cacbe54f65899fc3d5660.tar.bz2 perlweeklychallenge-club-8c97674d4297af94c60cacbe54f65899fc3d5660.zip | |
Added challenge 139 solution
| -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")
|
