aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuca Ferrari <fluca1978@gmail.com>2022-11-14 11:52:49 +0100
committerLuca Ferrari <fluca1978@gmail.com>2022-11-14 11:52:49 +0100
commit6e220c1639c9101b0968622e2ec9e0d4e0babc08 (patch)
tree08d055cb48c983ae45bf6026c1e916b7bb55a07f
parent36dd7f7ec23a79c31937377af3071eb3e9f358c0 (diff)
downloadperlweeklychallenge-club-6e220c1639c9101b0968622e2ec9e0d4e0babc08.tar.gz
perlweeklychallenge-club-6e220c1639c9101b0968622e2ec9e0d4e0babc08.tar.bz2
perlweeklychallenge-club-6e220c1639c9101b0968622e2ec9e0d4e0babc08.zip
Task 1 PL/Perl done
-rw-r--r--challenge-191/luca-ferrari/postgresql/ch-1.plperl36
1 files changed, 36 insertions, 0 deletions
diff --git a/challenge-191/luca-ferrari/postgresql/ch-1.plperl b/challenge-191/luca-ferrari/postgresql/ch-1.plperl
new file mode 100644
index 0000000000..321ae4b3a8
--- /dev/null
+++ b/challenge-191/luca-ferrari/postgresql/ch-1.plperl
@@ -0,0 +1,36 @@
+-- Perl Weekly Challenge 191
+-- Task 1
+
+CREATE SCHEMA IF NOT EXISTS pwc191;
+
+
+/*
+testdb=> select * from pwc191.task1_plperl( ARRAY[1,2,3,6]::int[] );
+ task1_plperl
+--------------
+ 1
+
+*/
+CREATE OR REPLACE FUNCTION
+pwc191.task1_plperl( int[] )
+RETURNS int
+AS $CODE$
+ my ($l) = @_;
+
+ my $max = 0;
+
+ # compute the max element
+ for ( $l->@* ) {
+ $max = $_ if ( $max < $_ );
+ }
+
+ # iterate on all elements and see
+ # if one of the is doubly greater than the max
+ for ( $l->@* ) {
+ next if $_ == $max;
+ return -1 if $_ * 2 > $max;
+ }
+
+ return 1;
+$CODE$
+LANGUAGE plperl;