aboutsummaryrefslogtreecommitdiff
path: root/challenge-109
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2021-04-19 23:09:06 +0100
committerGitHub <noreply@github.com>2021-04-19 23:09:06 +0100
commit716591a3fd756459daece6f38e45ad3292fae5b4 (patch)
tree3a5053b5fa0b5eebed8097c941773f92d08eadbd /challenge-109
parent34127c5a580e9072976492b7dc73482b0fdc27ec (diff)
parent351520fb3707600002f0af975f0276d0b6d13aa7 (diff)
downloadperlweeklychallenge-club-716591a3fd756459daece6f38e45ad3292fae5b4.tar.gz
perlweeklychallenge-club-716591a3fd756459daece6f38e45ad3292fae5b4.tar.bz2
perlweeklychallenge-club-716591a3fd756459daece6f38e45ad3292fae5b4.zip
Merge pull request #3928 from stuart-little/stuart-little_109_perl
1st commit on 109_perl
Diffstat (limited to 'challenge-109')
-rwxr-xr-xchallenge-109/stuart-little/perl/ch-1.pl7
-rwxr-xr-xchallenge-109/stuart-little/perl/ch-2.pl30
2 files changed, 37 insertions, 0 deletions
diff --git a/challenge-109/stuart-little/perl/ch-1.pl b/challenge-109/stuart-little/perl/ch-1.pl
new file mode 100755
index 0000000000..40c307afbc
--- /dev/null
+++ b/challenge-109/stuart-little/perl/ch-1.pl
@@ -0,0 +1,7 @@
+#!/usr/bin/perl
+use warnings;
+use v5.12;
+
+# run <script>
+
+say "0, 0, 0, 2, 0, 5, 0, 6, 3, 7, 0, 15, 0, 9, 8, 14, 0, 20, 0, 21";
diff --git a/challenge-109/stuart-little/perl/ch-2.pl b/challenge-109/stuart-little/perl/ch-2.pl
new file mode 100755
index 0000000000..da8429bebf
--- /dev/null
+++ b/challenge-109/stuart-little/perl/ch-2.pl
@@ -0,0 +1,30 @@
+#!/usr/bin/perl
+use warnings;
+use v5.12;
+
+# run <script> <space-separated numbers>
+
+use feature qw(signatures);
+no warnings qw(experimental::signatures);
+
+use Algorithm::Permute qw(permute);
+use List::AllUtils qw(sum min all pairwise);
+
+sub checkSameSums($aref) {
+ my $len = scalar @{$aref};
+ return all {$_ == sum $aref->@[0,1]} map {sum $aref->@[2*$_-1..(min(2*$_+1,$len-1))]} (1..(int $len/2));
+}
+
+sub pprnt($aref) {
+ my @letters = ('a'..'g');
+ my @strngs = pairwise {qq|$a = $b|} @letters, @{$aref};
+ return join(', ', @strngs);
+}
+
+my $solCount=0;
+
+permute { if (checkSameSums(\@ARGV)) {$solCount++; my $out = pprnt(\@ARGV); say "Solution: $out\nSum: ${\ do{sum @ARGV[0,1]}}\n"} } @ARGV;
+
+(! $solCount) && do {
+ say "No solution."
+}