aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-207/luca-ferrari/postgresql/ch-2.plperl23
1 files changed, 23 insertions, 0 deletions
diff --git a/challenge-207/luca-ferrari/postgresql/ch-2.plperl b/challenge-207/luca-ferrari/postgresql/ch-2.plperl
new file mode 100644
index 0000000000..1f31604070
--- /dev/null
+++ b/challenge-207/luca-ferrari/postgresql/ch-2.plperl
@@ -0,0 +1,23 @@
+--
+-- Perl Weekly Challenge 207
+-- Task 2
+-- See <https://perlweeklychallenge.org/blog/perl-weekly-challenge-207/>
+--
+
+CREATE SCHEMA IF NOT EXISTS pwc207;
+
+CREATE OR REPLACE FUNCTION
+pwc207.task2_plperl( int[] )
+RETURNS int
+AS $CODE$
+
+ my ( $citations ) = @_;
+ my @cits = reverse sort $citations->@*;
+ my @data;
+ while ( my ( $key, $value ) = each( @cits ) ) {
+ push @data, $value if ( $key >= $value );
+ }
+
+ return ( sort( @data ) )[ 0 ];
+$CODE$
+LANGUAGE plperl;