diff options
| author | Steven Wilson <steven1170@zoho.eu> | 2021-11-17 10:38:29 +0000 |
|---|---|---|
| committer | Steven Wilson <steven1170@zoho.eu> | 2021-11-17 10:38:29 +0000 |
| commit | f7a7cad2998ddcb34ccb46744c065fd32f25c9e6 (patch) | |
| tree | c5b5e7b2808811b302c3f5b667073a2cf614e313 | |
| parent | 7920f07d10c5eef33a44fc4eac0a40eab3a52b32 (diff) | |
| download | perlweeklychallenge-club-f7a7cad2998ddcb34ccb46744c065fd32f25c9e6.tar.gz perlweeklychallenge-club-f7a7cad2998ddcb34ccb46744c065fd32f25c9e6.tar.bz2 perlweeklychallenge-club-f7a7cad2998ddcb34ccb46744c065fd32f25c9e6.zip | |
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; +} |
