diff options
| author | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2021-11-20 09:54:38 +0000 |
|---|---|---|
| committer | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2021-11-20 09:54:38 +0000 |
| commit | 7b14c8a61e9ef869205501e383260dbac4212c86 (patch) | |
| tree | 7026f4f108b88d92a6957d815a0e35949b52cbee /challenge-139 | |
| parent | e07c2ddd5c20d692cbfa5fc6fe8872c1a28e3737 (diff) | |
| download | perlweeklychallenge-club-7b14c8a61e9ef869205501e383260dbac4212c86.tar.gz perlweeklychallenge-club-7b14c8a61e9ef869205501e383260dbac4212c86.tar.bz2 perlweeklychallenge-club-7b14c8a61e9ef869205501e383260dbac4212c86.zip | |
- Added solutions to "JortSort" of week 139.
Diffstat (limited to 'challenge-139')
| -rw-r--r-- | challenge-139/mohammad-anwar/perl/ch-1.pl | 36 | ||||
| -rw-r--r-- | challenge-139/mohammad-anwar/raku/ch-1.raku | 36 |
2 files changed, 72 insertions, 0 deletions
diff --git a/challenge-139/mohammad-anwar/perl/ch-1.pl b/challenge-139/mohammad-anwar/perl/ch-1.pl new file mode 100644 index 0000000000..e2351dc0fe --- /dev/null +++ b/challenge-139/mohammad-anwar/perl/ch-1.pl @@ -0,0 +1,36 @@ +#!/usr/bin/perl + +=head1 + +Week 139: + + https://theweeklychallenge.org/blog/perl-weekly-challenge-139 + +Task #1: JortSort + + 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. + +=cut + +use strict; +use warnings; + +use Test::More; + +is(jortsort(1,2,3,4,5), 1, 'Example 1'); +is(jortsort(1,3,2,4,5), 0, 'Example 2'); + +done_testing; + +sub jortsort { + my (@n) = @_; + + my @s = sort @n; + foreach my $i (0 .. @n-1) { + return 0 if ($s[$i] != $n[$i]); + } + + return 1; +} diff --git a/challenge-139/mohammad-anwar/raku/ch-1.raku b/challenge-139/mohammad-anwar/raku/ch-1.raku new file mode 100644 index 0000000000..c7a0e2c6fd --- /dev/null +++ b/challenge-139/mohammad-anwar/raku/ch-1.raku @@ -0,0 +1,36 @@ +#!/usr/bin/env raku + +=begin pod + +Week 139: + + https://theweeklychallenge.org/blog/perl-weekly-challenge-139 + +Task #1: JortSort + + 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. + +=end pod + +use Test; + +is jortsort([1,2,3,4,5]), True, 'Example 1'; +is jortsort([1,3,2,4,5]), False, 'Example 2'; + +done-testing; + +# +# +# METHODS + +sub jortsort(@n where @n.elems ~~ Int --> Bool) { + + my @s = @n.sort; + for 0 .. @n-1 -> $i { + return False if @n[$i] != @s[$i]; + } + + return True; +} |
