aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad Sajid Anwar <Mohammad.Anwar@yahoo.com>2023-12-04 20:46:13 +0000
committerGitHub <noreply@github.com>2023-12-04 20:46:13 +0000
commit3ddd9931467aad96a95298d894d7fa3e1cbf4a0d (patch)
tree2c08483e32598e30894de202c8590cf0bee6fedc
parent6338de7712d7da1e509995af89ed80275390795b (diff)
parente43aa708dc347d0db8c0fb1e914b5015b7fb85c8 (diff)
downloadperlweeklychallenge-club-3ddd9931467aad96a95298d894d7fa3e1cbf4a0d.tar.gz
perlweeklychallenge-club-3ddd9931467aad96a95298d894d7fa3e1cbf4a0d.tar.bz2
perlweeklychallenge-club-3ddd9931467aad96a95298d894d7fa3e1cbf4a0d.zip
Merge pull request #9194 from jacoby/master
coded 246
-rw-r--r--challenge-246/dave-jacoby/perl/ch-1.pl14
-rw-r--r--challenge-246/dave-jacoby/perl/ch-2.pl43
2 files changed, 57 insertions, 0 deletions
diff --git a/challenge-246/dave-jacoby/perl/ch-1.pl b/challenge-246/dave-jacoby/perl/ch-1.pl
new file mode 100644
index 0000000000..6b58ba3912
--- /dev/null
+++ b/challenge-246/dave-jacoby/perl/ch-1.pl
@@ -0,0 +1,14 @@
+#!/usr/bin/env perl
+
+use strict;
+use warnings;
+use experimental qw{ say postderef signatures state };
+
+say join "\n",
+ sort { $a <=> $b } # and the example is sorted numerically, so we will
+ map { 1 + int rand 49 } # which are random and between 1 and 49
+ # but int rand ( n ) will give a number between 0 and n-1
+ # so adding 1 will put it at the right range
+ 1 .. 6; # we want six numbers
+
+
diff --git a/challenge-246/dave-jacoby/perl/ch-2.pl b/challenge-246/dave-jacoby/perl/ch-2.pl
new file mode 100644
index 0000000000..2cf6806510
--- /dev/null
+++ b/challenge-246/dave-jacoby/perl/ch-2.pl
@@ -0,0 +1,43 @@
+#!/usr/bin/env perl
+
+use strict;
+use warnings;
+use experimental qw{ say postderef signatures state };
+
+use Algorithm::Combinatorics qw{ variations };
+
+my @examples = (
+
+ [ 1, 1, 2, 3, 5 ],
+ [ 4, 2, 4, 5, 7 ],
+ [ 4, 1, 2, -3, 8 ],
+);
+
+for my $e (@examples) {
+ my $input = join ', ', $e->@*;
+ my $output = lrso( $e->@* );
+
+ say <<~"END";
+ Input: \$input = ($input)
+ Output: $output
+ END
+}
+
+sub lrso (@input) {
+OUTER: for my $n ( 2 .. -1 + scalar @input ) {
+ for my $p ( 1 .. 100 ) {
+ for my $pp ( 1, -1 ) {
+ my $ppp = ( $p * $pp ) * $input[ $n - 2 ];
+ for my $q ( 1 .. 100 ) {
+ for my $qq ( 1, -1 ) {
+ my $qqq = ( $q * $qq ) * $input[ $n - 1 ];
+ my $rrr = $ppp + $qqq;
+ next OUTER if $rrr == $input[$n];
+ }
+ }
+ }
+ }
+ return 'false';
+ }
+ return 'true';
+}