diff options
| author | James Smith <js5@sanger.ac.uk> | 2022-12-19 09:06:53 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-12-19 09:06:53 +0000 |
| commit | 5622cc99422fbf8389c0b02c727f40863307fe25 (patch) | |
| tree | 250a0bece59d30ba030a4f9c368b7406e71fe23e | |
| parent | d0495985bdee0af409e7301b6b37dd6fe063f4d7 (diff) | |
| download | perlweeklychallenge-club-5622cc99422fbf8389c0b02c727f40863307fe25.tar.gz perlweeklychallenge-club-5622cc99422fbf8389c0b02c727f40863307fe25.tar.bz2 perlweeklychallenge-club-5622cc99422fbf8389c0b02c727f40863307fe25.zip | |
Create ch-1.pl
| -rw-r--r-- | challenge-196/james-smith/ch-1.pl | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/challenge-196/james-smith/ch-1.pl b/challenge-196/james-smith/ch-1.pl new file mode 100644 index 0000000000..46c361058b --- /dev/null +++ b/challenge-196/james-smith/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..$#_] + } + } + () +} |
