aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuca Ferrari <fluca1978@gmail.com>2022-12-06 08:11:03 +0100
committerLuca Ferrari <fluca1978@gmail.com>2022-12-06 08:11:03 +0100
commitad7fc62af9ff6f45cb1585a0ad87f382452f6a6f (patch)
treee1c59b118bbe7d1c3e38614f6984f358afa68288
parent345f4b5979521b5905cf91c460a1e6217e9f4b2f (diff)
downloadperlweeklychallenge-club-ad7fc62af9ff6f45cb1585a0ad87f382452f6a6f.tar.gz
perlweeklychallenge-club-ad7fc62af9ff6f45cb1585a0ad87f382452f6a6f.tar.bz2
perlweeklychallenge-club-ad7fc62af9ff6f45cb1585a0ad87f382452f6a6f.zip
Task 2 plperl done
-rw-r--r--challenge-194/luca-ferrari/postgresql/ch-2.plperl26
1 files changed, 26 insertions, 0 deletions
diff --git a/challenge-194/luca-ferrari/postgresql/ch-2.plperl b/challenge-194/luca-ferrari/postgresql/ch-2.plperl
new file mode 100644
index 0000000000..492213c917
--- /dev/null
+++ b/challenge-194/luca-ferrari/postgresql/ch-2.plperl
@@ -0,0 +1,26 @@
+-- Perl Weekly Challenge 194
+-- Task 2
+
+CREATE SCHEMA IF NOT EXISTS pwc194;
+
+CREATE OR REPLACE FUNCTION
+pwc194.task2_plperl( text )
+RETURNS int
+AS $CODE$
+ my ( $what ) = @_;
+
+ my %counter;
+ my ( $max, $min ) = ( 0, 0 );
+
+ for ( split '', $what ) {
+ $counter{ $_ }++;
+ $min = $counter{ $_ } if ( ! $min || $min > $counter{ $_ } );
+ $max = $counter{ $_ } if ( ! $max || $max < $counter{ $_ } );
+ }
+
+ return 0 if ( $max - $min != 1 );
+ return 0 if ( grep( { $counter{ $_ } == $max } keys %counter ) != 1 );
+ return 1;
+
+$CODE$
+LANGUAGE plperl;