aboutsummaryrefslogtreecommitdiff
path: root/challenge-276
diff options
context:
space:
mode:
authorMohammad S Anwar <mohammad.anwar@yahoo.com>2024-07-04 12:25:56 +0100
committerMohammad S Anwar <mohammad.anwar@yahoo.com>2024-07-04 12:25:56 +0100
commited2022e470f4f8e3d46e094fd0eb8e3b6d8ffddf (patch)
treed9a48f059428aa9e71afdfd45fdbdf7c63353d58 /challenge-276
parent884c521c4a2d6bdd80eee7ff296ff6f2f235c349 (diff)
downloadperlweeklychallenge-club-ed2022e470f4f8e3d46e094fd0eb8e3b6d8ffddf.tar.gz
perlweeklychallenge-club-ed2022e470f4f8e3d46e094fd0eb8e3b6d8ffddf.tar.bz2
perlweeklychallenge-club-ed2022e470f4f8e3d46e094fd0eb8e3b6d8ffddf.zip
- Added solutions by Laurent Rosenfeld.
- Added solutions by Reinier Maliepaard. - Added solutions by Luca Ferrari. - Added solutions by Packy Anderson. - Added solutions by Ali Moradi.
Diffstat (limited to 'challenge-276')
-rw-r--r--challenge-276/laurent-rosenfeld/blog.txt1
-rw-r--r--challenge-276/laurent-rosenfeld/perl/ch-1.pl21
-rw-r--r--challenge-276/laurent-rosenfeld/raku/ch-1.raku12
-rw-r--r--challenge-276/reinier-maliepaard/blog.txt1
-rw-r--r--challenge-276/reinier-maliepaard/perl/ch-1.pl36
-rw-r--r--challenge-276/reinier-maliepaard/perl/ch-2.pl37
6 files changed, 108 insertions, 0 deletions
diff --git a/challenge-276/laurent-rosenfeld/blog.txt b/challenge-276/laurent-rosenfeld/blog.txt
new file mode 100644
index 0000000000..0a72abba6c
--- /dev/null
+++ b/challenge-276/laurent-rosenfeld/blog.txt
@@ -0,0 +1 @@
+https://blogs.perl.org/users/laurent_r/2024/07/perl-weekly-challenge-276-complete-day.html
diff --git a/challenge-276/laurent-rosenfeld/perl/ch-1.pl b/challenge-276/laurent-rosenfeld/perl/ch-1.pl
new file mode 100644
index 0000000000..3c6b15a0ba
--- /dev/null
+++ b/challenge-276/laurent-rosenfeld/perl/ch-1.pl
@@ -0,0 +1,21 @@
+use strict;
+use warnings;
+use feature 'say';
+
+
+sub complete_day {
+ my @in = @_;
+ my $count = 0;
+ for my $i (0..$#in) {
+ for my $j ($i+1..$#in) {
+ $count++ if ($in[$i] + $in[$j]) % 24 == 0;
+ }
+ }
+ return $count;
+}
+
+my @tests = ([<12 12 30 24 24>], [<72 48 24 5>], [<12 18 24>]);
+for my $test (@tests) {
+ printf "%-15s => ", "@$test";
+ say complete_day @$test;
+}
diff --git a/challenge-276/laurent-rosenfeld/raku/ch-1.raku b/challenge-276/laurent-rosenfeld/raku/ch-1.raku
new file mode 100644
index 0000000000..891678b100
--- /dev/null
+++ b/challenge-276/laurent-rosenfeld/raku/ch-1.raku
@@ -0,0 +1,12 @@
+sub complete-day (@in) {
+ my $count = 0;
+ for @in.combinations: 2 -> @pair {
+ $count++ if ([+] @pair) %% 24;
+ }
+ return $count;
+
+my @tests = <12 12 30 24 24>, <72 48 24 5>, <12 18 24>;
+for @tests -> @test {
+ printf "%-15s => ", "@test[]";
+ say complete-day @test;
+}
diff --git a/challenge-276/reinier-maliepaard/blog.txt b/challenge-276/reinier-maliepaard/blog.txt
new file mode 100644
index 0000000000..54151a6a28
--- /dev/null
+++ b/challenge-276/reinier-maliepaard/blog.txt
@@ -0,0 +1 @@
+https://reiniermaliepaard.nl/perl/pwc/index.php?id=pwc276
diff --git a/challenge-276/reinier-maliepaard/perl/ch-1.pl b/challenge-276/reinier-maliepaard/perl/ch-1.pl
new file mode 100644
index 0000000000..a049f09289
--- /dev/null
+++ b/challenge-276/reinier-maliepaard/perl/ch-1.pl
@@ -0,0 +1,36 @@
+#!/usr/bin/perl
+use strict;
+use warnings;
+
+use Math::Combinatorics;
+
+sub complete_day {
+
+ my $c = Math::Combinatorics->new ( count => 2, data => [@_], );
+
+ my $count = 0;
+
+ while ( my @cmb = $c->next_combination ) {
+
+ $count++ if ( ($cmb[0] + $cmb[1]) % 24 == 0 );
+
+ }
+
+ return ($count);
+}
+
+# Tests
+
+my (@hours);
+
+# Example 1
+@hours = (12, 12, 30, 24, 24);
+print(complete_day(@hours), "\n"); # Output: 2
+
+# Example 2
+@hours = (72, 48, 24, 5);
+print(complete_day(@hours), "\n"); # Output: 3
+
+# Example 3
+@hours = (12, 18, 24);
+print(complete_day(@hours), "\n"); # Output: 0
diff --git a/challenge-276/reinier-maliepaard/perl/ch-2.pl b/challenge-276/reinier-maliepaard/perl/ch-2.pl
new file mode 100644
index 0000000000..c8a75a2b00
--- /dev/null
+++ b/challenge-276/reinier-maliepaard/perl/ch-2.pl
@@ -0,0 +1,37 @@
+#!/usr/bin/perl
+use strict;
+use warnings;
+
+use Statistics::Frequency;
+
+sub max_freq {
+
+ my ($count, $f, %freq) = (0);
+
+ $f = Statistics::Frequency->new( @_ );
+ %freq = $f->frequencies;
+
+ $count += $f->frequencies_max for ( grep { $_ == $f->frequencies_max } values %freq );
+
+ return ($count);
+}
+
+# Tests
+
+my (@ints);
+
+# Example 1
+@ints = (1, 2, 2, 4, 1, 5);
+print(max_freq((@ints)), "\n"); # Output: 4
+
+# Example 2
+@ints = (1, 2, 3, 4, 5);
+print(max_freq((@ints)), "\n"); # Output: 5
+
+# Example 3
+@ints = (1, 1, 3, 3, 3, 3);
+print(max_freq((@ints)), "\n"); # Output: 4
+
+# Example 4
+@ints = (1, 2, 2, 4);
+print(max_freq((@ints)), "\n"); # Output: 2