aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorchirvasitua <stuart-little@users.noreply.github.com>2021-08-02 09:00:06 -0400
committerchirvasitua <stuart-little@users.noreply.github.com>2021-08-02 09:00:06 -0400
commit0f4411f0fb3481575d565fdac12eefabf8b4b472 (patch)
treee002535c7b73b09310892bcdf7580978589a6008
parentf98b461d6301c6fc12e60034ec0677185ebac33c (diff)
downloadperlweeklychallenge-club-0f4411f0fb3481575d565fdac12eefabf8b4b472.tar.gz
perlweeklychallenge-club-0f4411f0fb3481575d565fdac12eefabf8b4b472.tar.bz2
perlweeklychallenge-club-0f4411f0fb3481575d565fdac12eefabf8b4b472.zip
1st commit on 124_perl
-rwxr-xr-xchallenge-124/stuart-little/perl/ch-1.pl26
-rwxr-xr-xchallenge-124/stuart-little/perl/ch-2.pl22
2 files changed, 48 insertions, 0 deletions
diff --git a/challenge-124/stuart-little/perl/ch-1.pl b/challenge-124/stuart-little/perl/ch-1.pl
new file mode 100755
index 0000000000..36e1931171
--- /dev/null
+++ b/challenge-124/stuart-little/perl/ch-1.pl
@@ -0,0 +1,26 @@
+#!/usr/bin/env perl
+use warnings;
+use v5.12;
+
+# run <script>
+
+my $msg = <<"EOF";
+ ^^^^^
+ ^ ^
+ ^ ^
+ ^ ^
+ ^ ^
+ ^ ^
+ ^ ^
+ ^ ^
+ ^ ^
+ ^ ^
+ ^^^^^
+ ^
+ ^
+ ^
+ ^^^^^
+ ^
+ ^
+EOF
+say $msg;
diff --git a/challenge-124/stuart-little/perl/ch-2.pl b/challenge-124/stuart-little/perl/ch-2.pl
new file mode 100755
index 0000000000..8626ddbc13
--- /dev/null
+++ b/challenge-124/stuart-little/perl/ch-2.pl
@@ -0,0 +1,22 @@
+#!/usr/bin/env perl
+use warnings;
+use v5.12;
+
+# run <script> <space-separated numbers>
+
+use feature qw(signatures);
+no warnings qw(experimental::signatures);
+
+use Data::PowerSet qw(powerset);
+use List::AllUtils qw(sum0 min_by);
+use Set::Scalar;
+
+sub splt($ar) {
+ my $powerSet = powerset({min => int(scalar @{$ar}/2), max => int(scalar @{$ar}/2)}, @{$ar});
+ my $set = Set::Scalar->new(@{$ar});
+ return min_by {abs((sum0 @{$_->[0]}) - (sum0 @{$_->[1]}))} map {my @diff = $set->difference(Set::Scalar->new(@{$_}))->members; [$_, \@diff]} @{$powerSet};
+}
+
+my $splt = splt(\@ARGV);
+say "@{$splt->[0]}";
+say "@{$splt->[1]}";