aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuis Mochan <mochan@fis.unam.mx>2022-07-25 11:38:16 -0500
committerLuis Mochan <mochan@fis.unam.mx>2022-07-25 11:38:16 -0500
commitddd259a3e47afc2e28beef49389b4c548cb4f0f0 (patch)
tree87e6dc0686d940c569f8eb0d0268808fd384045f
parente917de3d5ca5b4986a52fb59546fda4bff5dd57c (diff)
downloadperlweeklychallenge-club-ddd259a3e47afc2e28beef49389b4c548cb4f0f0.tar.gz
perlweeklychallenge-club-ddd259a3e47afc2e28beef49389b4c548cb4f0f0.tar.bz2
perlweeklychallenge-club-ddd259a3e47afc2e28beef49389b4c548cb4f0f0.zip
Solve PWC175
-rw-r--r--challenge-175/wlmb/blog.txt1
-rwxr-xr-xchallenge-175/wlmb/perl/ch-1.pl14
-rwxr-xr-xchallenge-175/wlmb/perl/ch-2.pl21
3 files changed, 36 insertions, 0 deletions
diff --git a/challenge-175/wlmb/blog.txt b/challenge-175/wlmb/blog.txt
new file mode 100644
index 0000000000..89123a871b
--- /dev/null
+++ b/challenge-175/wlmb/blog.txt
@@ -0,0 +1 @@
+https://wlmb.github.io/2022/07/25/PWC175/
diff --git a/challenge-175/wlmb/perl/ch-1.pl b/challenge-175/wlmb/perl/ch-1.pl
new file mode 100755
index 0000000000..ce801b34a9
--- /dev/null
+++ b/challenge-175/wlmb/perl/ch-1.pl
@@ -0,0 +1,14 @@
+#!/usr/bin/env perl
+# Perl weekly challenge 175
+# Task 1: Last Sunday
+#
+# See https://wlmb.github.io/2022/07/25/PWC175/#task-1-last-sunday
+use v5.36;
+use DateTime;
+die "Usage: $0 Y1 [Y2...]\nto print the last Sundays of years Y1, Y2...\n"
+ unless @ARGV;
+foreach my $year(@ARGV){
+ say "\nLast Sundays of year $year:";
+ say $_->subtract(days=>$_->day_of_week%7)->ymd for
+ map {DateTime->last_day_of_month(year=>$year, month=>$_)} (1..12)
+}
diff --git a/challenge-175/wlmb/perl/ch-2.pl b/challenge-175/wlmb/perl/ch-2.pl
new file mode 100755
index 0000000000..258905375f
--- /dev/null
+++ b/challenge-175/wlmb/perl/ch-2.pl
@@ -0,0 +1,21 @@
+#!/usr/bin/env perl
+# Perl weekly challenge 175
+# Task 2: Perfect totient numbers
+#
+# See https://wlmb.github.io/2022/07/25/PWC175/#task-2-perfect-totient-numbers
+use v5.36;
+use List::Util qw(sum);
+use Math::Prime::Util qw(euler_phi);
+die "Usage: $0 N\nto print the first N perfect totient numbers\n"
+ unless @ARGV;
+say "$_: ", next_perfect_totient() for(1..shift);
+sub next_perfect_totient{
+ state $current=1;
+ ++$current;
+ ++$current until $current==sum recursive_totients($current);
+ $current
+}
+sub recursive_totients($m){ #(totient(m), totient(totient($m))...)
+ my $t=euler_phi($m);
+ $m==2?($t):(recursive_totients($t), $t)
+}