aboutsummaryrefslogtreecommitdiff
path: root/challenge-234/deadmarshal/perl
diff options
context:
space:
mode:
authordeadmarshal <adeadmarshal@gmail.com>2023-09-14 21:52:47 +0330
committerdeadmarshal <adeadmarshal@gmail.com>2023-09-14 21:52:47 +0330
commitfb55e01eb26fa71188024303b387794e4d3b8f75 (patch)
tree8c802d97513e4af39d69d0c106f684d41f6847ef /challenge-234/deadmarshal/perl
parent3f85224aa3a84d4fb99755152cba5176cf49b795 (diff)
downloadperlweeklychallenge-club-fb55e01eb26fa71188024303b387794e4d3b8f75.tar.gz
perlweeklychallenge-club-fb55e01eb26fa71188024303b387794e4d3b8f75.tar.bz2
perlweeklychallenge-club-fb55e01eb26fa71188024303b387794e4d3b8f75.zip
TWC234
Diffstat (limited to 'challenge-234/deadmarshal/perl')
-rw-r--r--challenge-234/deadmarshal/perl/ch-1.pl20
-rw-r--r--challenge-234/deadmarshal/perl/ch-2.pl17
2 files changed, 37 insertions, 0 deletions
diff --git a/challenge-234/deadmarshal/perl/ch-1.pl b/challenge-234/deadmarshal/perl/ch-1.pl
new file mode 100644
index 0000000000..e2bb34d2a6
--- /dev/null
+++ b/challenge-234/deadmarshal/perl/ch-1.pl
@@ -0,0 +1,20 @@
+#!/usr/bin/env perl
+use strict;
+use warnings;
+use List::Util qw(min);
+
+sub common_characters{
+ my @letters;
+ map{my %h; $h{$_}++ for split ''; push @letters,\%h} @{$_[0]};
+ map{my $letter = $_;
+ my $rep = min map{$letters[$_]{$letter} // 0} 0..$#letters;
+ ($letter) x $rep
+ } keys %{$letters[0]};
+}
+
+printf "(%s)\n", join ',',
+ common_characters([qw/java javascript julia/]);
+printf "(%s)\n", join ',',
+ common_characters([qw/bella label roller/]);
+printf "(%s)\n", join ',', common_characters([qw/cool lock cook/]);
+
diff --git a/challenge-234/deadmarshal/perl/ch-2.pl b/challenge-234/deadmarshal/perl/ch-2.pl
new file mode 100644
index 0000000000..d95f4d6920
--- /dev/null
+++ b/challenge-234/deadmarshal/perl/ch-2.pl
@@ -0,0 +1,17 @@
+#!/usr/bin/env perl
+use strict;
+use warnings;
+use List::Util qw(sum0 product);
+use Algorithm::Combinatorics qw(combinations);
+
+sub unequal_triplets{
+ my %h;
+ $h{$_}++ foreach @{$_[0]};
+ my @keys = keys %h;
+ @keys < 3 ? 0 : sum0 map{product @h{@$_}} combinations(\@keys,3);
+}
+
+printf "%d\n", unequal_triplets([4,4,2,4,3]);
+printf "%d\n", unequal_triplets([1,1,1,1,1]);
+printf "%d\n", unequal_triplets([4,7,1,10,7,4,1,1]);
+