From 8c97674d4297af94c60cacbe54f65899fc3d5660 Mon Sep 17 00:00:00 2001 From: Cris-HD Date: Tue, 16 Nov 2021 18:06:30 +0100 Subject: Added challenge 139 solution --- challenge-139/cristian-heredia/perl/ch_1.pl | 36 +++++++++++++++++++++++++++ challenge-139/cristian-heredia/python/ch_1.py | 30 ++++++++++++++++++++++ 2 files changed, 66 insertions(+) create mode 100755 challenge-139/cristian-heredia/perl/ch_1.pl create mode 100755 challenge-139/cristian-heredia/python/ch_1.py 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") -- cgit