diff options
| author | Luca Ferrari <fluca1978@gmail.com> | 2023-09-17 18:49:26 +0200 |
|---|---|---|
| committer | Luca Ferrari <fluca1978@gmail.com> | 2023-09-17 18:49:26 +0200 |
| commit | 60080f94b1cd0ff7dd6eb0dc3df3fd62feb3ae6a (patch) | |
| tree | d38c3223d95e37308fff8778de5b7fc72e21a3b2 | |
| parent | 3eeb198e7d789360e0c7f8e88566593b17f519c6 (diff) | |
| download | perlweeklychallenge-club-60080f94b1cd0ff7dd6eb0dc3df3fd62feb3ae6a.tar.gz perlweeklychallenge-club-60080f94b1cd0ff7dd6eb0dc3df3fd62feb3ae6a.tar.bz2 perlweeklychallenge-club-60080f94b1cd0ff7dd6eb0dc3df3fd62feb3ae6a.zip | |
Task 1 plperl done
| -rw-r--r-- | challenge-234/luca-ferrari/postgresql/ch-1.plperl | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/challenge-234/luca-ferrari/postgresql/ch-1.plperl b/challenge-234/luca-ferrari/postgresql/ch-1.plperl new file mode 100644 index 0000000000..6edef0543c --- /dev/null +++ b/challenge-234/luca-ferrari/postgresql/ch-1.plperl @@ -0,0 +1,31 @@ +-- +-- Perl Weekly Challenge 234 +-- Task 1 +-- See <https://perlweeklychallenge.org/blog/perl-weekly-challenge-234/> +-- + +CREATE SCHEMA IF NOT EXISTS pwc234; + +CREATE OR REPLACE FUNCTION +pwc234.task1_plperl( text[] ) +RETURNS SETOF char +AS $CODE$ + my ( $words ) = @_; + + my $chars = {}; + + for my $current_word ( $words->@* ) { + for my $current_char ( sort split //, $current_word ) { + if ( ! grep { $_ eq $current_word } $chars->{ $current_char }->@* ) { + push $chars->{ $current_char }->@*, $current_word; + } + } + } + + for my $current_char ( keys $chars->%* ) { + return_next( $current_char ) if ( $chars->{ $current_char }->@* == scalar $words->@* ); + } + + return undef; +$CODE$ +LANGUAGE plperl; |
