aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDave Jacoby <jacoby.david@gmail.com>2024-07-01 18:41:41 -0400
committerDave Jacoby <jacoby.david@gmail.com>2024-07-01 18:41:41 -0400
commitd3c02bd425eb20869a0a1a7260fbf2ae83b0b44f (patch)
tree576e939231cb2748cbdf5b4a8a7eccc37c20f789
parentf18cb7a95e46b9ded70a2d1d932d0bb7b1772a67 (diff)
downloadperlweeklychallenge-club-d3c02bd425eb20869a0a1a7260fbf2ae83b0b44f.tar.gz
perlweeklychallenge-club-d3c02bd425eb20869a0a1a7260fbf2ae83b0b44f.tar.bz2
perlweeklychallenge-club-d3c02bd425eb20869a0a1a7260fbf2ae83b0b44f.zip
DAJ 276
-rw-r--r--challenge-276/dave-jacoby/perl/ch-1.pl35
-rw-r--r--challenge-276/dave-jacoby/perl/ch-2.pl31
2 files changed, 66 insertions, 0 deletions
diff --git a/challenge-276/dave-jacoby/perl/ch-1.pl b/challenge-276/dave-jacoby/perl/ch-1.pl
new file mode 100644
index 0000000000..93b58c6871
--- /dev/null
+++ b/challenge-276/dave-jacoby/perl/ch-1.pl
@@ -0,0 +1,35 @@
+#!/usr/bin/env perl
+
+use strict;
+use warnings;
+use experimental qw{ bitwise fc postderef say signatures state };
+
+use List::Util qw{max};
+
+my @examples = (
+
+ [ 12, 12, 30, 24, 24 ],
+ [ 72, 48, 24, 5 ],
+ [ 12, 18, 24 ],
+);
+
+for my $example (@examples) {
+ my $output = complete_day($example);
+ my $input = join ', ', $example->@*;
+ say <<~"END";
+ Input: \@hours = ($input)
+ Output: $output
+ END
+}
+
+sub complete_day ($durations) {
+ my @output;
+ my @durations = $durations->@*;
+ for my $i ( 0 .. -1 + scalar @durations ) {
+ for my $j ( $i + 1 .. -1 + scalar @durations ) {
+ my $d = $durations[$i] + $durations[$j];
+ push @output, [ $durations[$i], $durations[$j] ] if $d % 24 == 0;
+ }
+ }
+ return scalar @output;
+}
diff --git a/challenge-276/dave-jacoby/perl/ch-2.pl b/challenge-276/dave-jacoby/perl/ch-2.pl
new file mode 100644
index 0000000000..fc837e272d
--- /dev/null
+++ b/challenge-276/dave-jacoby/perl/ch-2.pl
@@ -0,0 +1,31 @@
+#!/usr/bin/env perl
+
+use strict;
+use warnings;
+use experimental qw{ fc say postderef signatures state };
+
+use List::Util qw{ max };
+
+my @examples = (
+
+[1, 2, 2, 4, 1, 5],
+[1, 2, 3, 4, 5],
+);
+
+for my $input (@examples) {
+ my $output = max_freq($input->@*);
+ my $ints = join ', ', $input->@*;
+
+ say <<"END";
+ Input: \@ints = ($ints)
+ Output: $output
+END
+}
+
+sub max_freq ( @ints ) {
+ my %hash ;
+ map { $hash{$_}++ } @ints;
+ my $max = max values %hash;
+ my @keys = grep { $hash{$_} == $max } keys %hash;
+ return $max * scalar @keys;
+} \ No newline at end of file