aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Smith <js5@sanger.ac.uk>2022-12-19 09:12:31 +0000
committerGitHub <noreply@github.com>2022-12-19 09:12:31 +0000
commitee22f2d6123096d39049f40e6b59df51902eaf25 (patch)
tree074aa1a0dda593ce21ba48cc48f2d073ba8d993f
parentb6300ccb79c3911b759033f5d751661916ac5520 (diff)
downloadperlweeklychallenge-club-ee22f2d6123096d39049f40e6b59df51902eaf25.tar.gz
perlweeklychallenge-club-ee22f2d6123096d39049f40e6b59df51902eaf25.tar.bz2
perlweeklychallenge-club-ee22f2d6123096d39049f40e6b59df51902eaf25.zip
Create ch-1.pl
-rw-r--r--challenge-196/james-smith/perl/ch-1.pl26
1 files changed, 26 insertions, 0 deletions
diff --git a/challenge-196/james-smith/perl/ch-1.pl b/challenge-196/james-smith/perl/ch-1.pl
new file mode 100644
index 0000000000..46c361058b
--- /dev/null
+++ b/challenge-196/james-smith/perl/ch-1.pl
@@ -0,0 +1,26 @@
+#!/usr/local/bin/perl
+
+use strict;
+use warnings;
+use feature qw(say);
+use Test::More;
+use Benchmark qw(cmpthese timethis);
+
+my @TESTS = (
+ [ [3,1,4,2], '3 4 2' ],
+ [ [1,2,3,4], '' ],
+ [ [1,3,2,4,6,5], '1 3 2' ],
+ [ [1,3,2], '1 3 2' ] );
+
+is( "@{[ pattern132( @{$_->[0]} ) ]}", $_->[1] ) for @TESTS;
+done_testing();
+
+sub pattern132 {
+ while(my$x=shift@_){
+ for my $i (0..$#_-1) {
+ next if $x > $_[$i];
+ ($x<$_)&&($_<=$_[$i])&&return $x,$_[$i],$_ for @_[$i+1..$#_]
+ }
+ }
+ ()
+}