diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2021-11-17 12:50:20 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-11-17 12:50:20 +0000 |
| commit | a70951fb9c525f97a84aea1f8a5f3922e3480a9a (patch) | |
| tree | 16cb79b1a1ac3a04af8a448755765de11826f347 | |
| parent | c10982923e463ca08cd07d5019beb759c1777701 (diff) | |
| parent | f7a7cad2998ddcb34ccb46744c065fd32f25c9e6 (diff) | |
| download | perlweeklychallenge-club-a70951fb9c525f97a84aea1f8a5f3922e3480a9a.tar.gz perlweeklychallenge-club-a70951fb9c525f97a84aea1f8a5f3922e3480a9a.tar.bz2 perlweeklychallenge-club-a70951fb9c525f97a84aea1f8a5f3922e3480a9a.zip | |
Merge pull request #5238 from oWnOIzRi/week139
add solution week 139 task 1 in perl
| -rw-r--r-- | challenge-139/steven-wilson/perl/ch-1.pl | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/challenge-139/steven-wilson/perl/ch-1.pl b/challenge-139/steven-wilson/perl/ch-1.pl new file mode 100644 index 0000000000..6178a43412 --- /dev/null +++ b/challenge-139/steven-wilson/perl/ch-1.pl @@ -0,0 +1,29 @@ +#!/usr/bin/env perl +# Week 139 Task 1 +# JortSort + +use strict; +use warnings; +use feature qw/ say /; +use Test::More; + +my @input1_t = qw/ 1 2 3 4 5 /; +my @input2_t = qw/ 1 3 2 4 5 /; +ok( jortsort( \@input1_t ) == 1, "Sorted" ); +ok( jortsort( \@input2_t ) == 0, "Unsorted" ); +done_testing(); + +sub jortsort { + my $input_ref = shift; + my @input = @{$input_ref}; + my @sorted_input = sort @input; + my $length = scalar @input; + my $sorted = 1; + for ( my $index = 0; $index < $length; $index++ ) { + if ( $input[$index] != $sorted_input[$index] ) { + $sorted = 0; + last; + } + } + return $sorted; +} |
