diff options
| author | drbaggy <js5@sanger.ac.uk> | 2022-10-18 07:33:03 +0100 |
|---|---|---|
| committer | drbaggy <js5@sanger.ac.uk> | 2022-10-18 07:33:03 +0100 |
| commit | 3af70dbf4eba617eb2df0538107375d8a37bdb77 (patch) | |
| tree | 8cf12399edfa9c5a87ae59b24ceadc91ec1fbffa | |
| parent | a9ff7e58cdc9ea345e05014805bcc7e652e7e307 (diff) | |
| download | perlweeklychallenge-club-3af70dbf4eba617eb2df0538107375d8a37bdb77.tar.gz perlweeklychallenge-club-3af70dbf4eba617eb2df0538107375d8a37bdb77.tar.bz2 perlweeklychallenge-club-3af70dbf4eba617eb2df0538107375d8a37bdb77.zip | |
realise most of the code is not needed
| -rw-r--r-- | challenge-187/james-smith/perl/ch-2.pl | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/challenge-187/james-smith/perl/ch-2.pl b/challenge-187/james-smith/perl/ch-2.pl index e08218ad26..006e0018d5 100644 --- a/challenge-187/james-smith/perl/ch-2.pl +++ b/challenge-187/james-smith/perl/ch-2.pl @@ -13,24 +13,35 @@ my @TESTS = ( [ [1,3,2], '' ], [ [1,1,2,3], '' ], [ [2,4,3], '4 3 2' ], + [ [1..10], '10 9 8' ], + [ [7,4,1], '' ], + [ [201,101,1], '' ], + [ [1,1,2,3,4,5,2,1,2,3,2,1,1,1,1,1], '5 4 3' ], ); +for( 1..100 ) { + my @T = map { 1 + int rand 20 } 1 .. 3 + int rand 17; + my $r = join ' ', (sort {$b<=>$a} @T)[0,1,2]; + push @TESTS, [ \@T, $r ] +} + + is( "@{[magical(@{$_->[0]})]}", $_->[1] ) foreach @TESTS; done_testing(); sub magical { @_ = sort { $b <=> $a } @_; - my @max = (0); while(@_>2) { my($a,$b,@c)=@_; while(@c) { - ($a+$b>$_) && ($b+$_>$a) && ($a+$_>$b) && ($a+$b+$_>$max[0]) && (@max=($a+$b+$_,$a,$b,$_)) for @c; + ($b+$_>$a) ? (return $a,$b,$_ ) : last for @c; $b = shift @c; } shift; } - shift @max; - @max; + (); + #shift @max; + #@max; } |
