aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad Sajid Anwar <Mohammad.Anwar@yahoo.com>2023-12-03 19:40:41 +0000
committerGitHub <noreply@github.com>2023-12-03 19:40:41 +0000
commitc0b292d9966817809cb54e6950690d4cdb7e5387 (patch)
tree7a4cef6f855691764b57a68766896953b40ff046
parent758c8b5490c35ce2a83dcc29d26488de87e591ff (diff)
parent24f03aa5bd6e1ef25774397437c52dc574d206bd (diff)
downloadperlweeklychallenge-club-c0b292d9966817809cb54e6950690d4cdb7e5387.tar.gz
perlweeklychallenge-club-c0b292d9966817809cb54e6950690d4cdb7e5387.tar.bz2
perlweeklychallenge-club-c0b292d9966817809cb54e6950690d4cdb7e5387.zip
Merge pull request #9176 from deadmarshal/TWC245
TWC245
-rw-r--r--challenge-245/deadmarshal/blog.txt1
-rw-r--r--challenge-245/deadmarshal/perl/ch-1.pl12
-rw-r--r--challenge-245/deadmarshal/perl/ch-2.pl23
3 files changed, 36 insertions, 0 deletions
diff --git a/challenge-245/deadmarshal/blog.txt b/challenge-245/deadmarshal/blog.txt
new file mode 100644
index 0000000000..9744565d32
--- /dev/null
+++ b/challenge-245/deadmarshal/blog.txt
@@ -0,0 +1 @@
+https://deadmarshal.blogspot.com/2023/12/twc245.html
diff --git a/challenge-245/deadmarshal/perl/ch-1.pl b/challenge-245/deadmarshal/perl/ch-1.pl
new file mode 100644
index 0000000000..757fa5bb5f
--- /dev/null
+++ b/challenge-245/deadmarshal/perl/ch-1.pl
@@ -0,0 +1,12 @@
+#!/usr/bin/env perl
+use strict;
+use warnings;
+use Data::Show;
+
+sub sort_language{
+ @{$_[0]}[map{$_-1}@{$_[1]}];
+}
+
+print show sort_language(['perl','c','python'],[2,1,3]);
+print show sort_language(['c++','haskell','java'],[1,3,2]);
+
diff --git a/challenge-245/deadmarshal/perl/ch-2.pl b/challenge-245/deadmarshal/perl/ch-2.pl
new file mode 100644
index 0000000000..5c67abf853
--- /dev/null
+++ b/challenge-245/deadmarshal/perl/ch-2.pl
@@ -0,0 +1,23 @@
+#!/usr/bin/env perl
+use strict;
+use warnings;
+use Algorithm::Combinatorics qw(permutations subsets);
+
+sub largest_of_three{
+ my $res = -1;
+ foreach my $i(0..@{$_[0]}){
+ foreach my $subset(subsets $_[0],$i){
+ foreach my $p(permutations $subset){
+ next unless @$p;
+ my $n = join '',@$p;
+ $res = $n if $n > $res && $n % 3 == 0;
+ }
+ }
+ }
+ $res
+}
+
+printf "%d\n",largest_of_three([8,1,9]);
+printf "%d\n",largest_of_three([8,6,7,1,0]);
+printf "%d\n",largest_of_three([1]);
+