aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDave Jacoby <jacoby.david@gmail.com>2023-11-13 14:47:20 -0500
committerDave Jacoby <jacoby.david@gmail.com>2023-11-13 14:47:20 -0500
commit0320f32cfb6178614d14587024958bba603866d6 (patch)
treec70a8700d5cec27e1aa179fe79868646b636cf97
parent2d88705542db47cb7618387dd74f91c4afe16361 (diff)
downloadperlweeklychallenge-club-0320f32cfb6178614d14587024958bba603866d6.tar.gz
perlweeklychallenge-club-0320f32cfb6178614d14587024958bba603866d6.tar.bz2
perlweeklychallenge-club-0320f32cfb6178614d14587024958bba603866d6.zip
DAJ 243
-rw-r--r--challenge-243/dave-jacoby/perl/ch-1.pl33
-rw-r--r--challenge-243/dave-jacoby/perl/ch-2.pl22
2 files changed, 55 insertions, 0 deletions
diff --git a/challenge-243/dave-jacoby/perl/ch-1.pl b/challenge-243/dave-jacoby/perl/ch-1.pl
new file mode 100644
index 0000000000..a54edcdb8d
--- /dev/null
+++ b/challenge-243/dave-jacoby/perl/ch-1.pl
@@ -0,0 +1,33 @@
+#!/usr/bin/env perl
+
+use strict;
+use warnings;
+use experimental qw{ say postderef signatures state };
+
+use List::Compare;
+
+my @examples = (
+
+ [ 1, 3, 2, 3, 1 ],
+ [ 2, 4, 3, 5, 1 ],
+);
+for my $e (@examples) {
+ my $output = reverse_pairs( $e->@* );
+ my $input = join ', ', $e->@*;
+ say <<~"END";
+ Input: \@input = ($input)
+ Output: $output
+ END
+}
+
+sub reverse_pairs (@input) {
+ my $output = 0;
+ for my $i ( 0 .. -1 + scalar @input ) {
+ my $ii = $input[$i];
+ for my $j ( $i + 1 .. -1 + scalar @input ) {
+ my $jj = $input[$j];
+ $output++ if $ii > $jj * 2;
+ }
+ }
+ return $output;
+}
diff --git a/challenge-243/dave-jacoby/perl/ch-2.pl b/challenge-243/dave-jacoby/perl/ch-2.pl
new file mode 100644
index 0000000000..75e04ed38e
--- /dev/null
+++ b/challenge-243/dave-jacoby/perl/ch-2.pl
@@ -0,0 +1,22 @@
+#!/usr/bin/env perl
+
+use strict;
+use warnings;
+use experimental qw{ say postderef signatures state };
+
+my @examples = (
+
+ [ 2, 5, 9 ],
+ [ 7, 7, 7, 7, 7, 7, 7 ],
+);
+
+for my $e (@examples) {
+ my $input = join ', ', $e->@*;
+ my $output = floor_sum( $e->@* );
+
+ say <<~"END";
+ Input: \$input = ($input)
+ Output: $output
+ END
+}
+sub floor_sum (@input) { my $output = 0; for my $i ( 0 .. -1 + scalar @input ) { my $ii = $input[$i]; for my $j ( 0 .. -1 + scalar @input ) { my $jj = $input[$j]; my $floor = int( $ii / $jj ); $output += $floor; } } return $output;} \ No newline at end of file