aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordeadmarshal <adeadmarshal@gmail.com>2023-12-03 10:50:45 -0500
committerdeadmarshal <adeadmarshal@gmail.com>2023-12-03 10:50:45 -0500
commit24f03aa5bd6e1ef25774397437c52dc574d206bd (patch)
treee711d0c7249267e9ffe4559180d20b573e5ee0ba
parent42f3795a1b6f04418786c0837278b58bc910511b (diff)
downloadperlweeklychallenge-club-24f03aa5bd6e1ef25774397437c52dc574d206bd.tar.gz
perlweeklychallenge-club-24f03aa5bd6e1ef25774397437c52dc574d206bd.tar.bz2
perlweeklychallenge-club-24f03aa5bd6e1ef25774397437c52dc574d206bd.zip
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]);
+