diff options
| -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..$#_] + } + } + () +} |
