From 8a928ad6f14f356646050cea4d105e7a8d519a05 Mon Sep 17 00:00:00 2001 From: Jan Krňávek Date: Sun, 31 Jul 2022 11:10:43 +0200 Subject: solutions week 175 --- challenge-175/wambash/raku/ch-1.raku | 32 ++++++++++++++++++++++++++++++++ challenge-175/wambash/raku/ch-2.raku | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+) create mode 100644 challenge-175/wambash/raku/ch-1.raku create mode 100644 challenge-175/wambash/raku/ch-2.raku diff --git a/challenge-175/wambash/raku/ch-1.raku b/challenge-175/wambash/raku/ch-1.raku new file mode 100644 index 0000000000..9c60d0524d --- /dev/null +++ b/challenge-175/wambash/raku/ch-1.raku @@ -0,0 +1,32 @@ +#!/usr/bin/env raku + +my $*this-year = Date.today.truncated-to('year'); + +multi last-sundays (Int $year) { + samewith Date.new: :$year +} + +multi last-sundays (Date $year = $*this-year) { + $year + andthen $_, *.later( :1month ) ...^ * + andthen .map: { .first-date-in-month .. .last-date-in-month }\ + andthen .map: *.first: *.day-of-week == 7, :end + andthen .head: 12 +} + +multi MAIN (Bool :test($)!) { + use Test; + is last-sundays(2022), < + 2022-01-30 2022-02-27 + 2022-03-27 2022-04-24 + 2022-05-29 2022-06-26 + 2022-07-31 2022-08-28 + 2022-09-25 2022-10-30 + 2022-11-27 2022-12-25 + >; + done-testing; +} + +multi MAIN (Int $year = 2022) { + put last-sundays $year; +} diff --git a/challenge-175/wambash/raku/ch-2.raku b/challenge-175/wambash/raku/ch-2.raku new file mode 100644 index 0000000000..153ea7a948 --- /dev/null +++ b/challenge-175/wambash/raku/ch-2.raku @@ -0,0 +1,33 @@ +#!/usr/bin/env raku + +use Prime::Factor; + +sub euler ($n) { + prime-factors($n) + andthen .Bag + andthen .map: { (.key-1) * .key**(.value-1) }\ + andthen [*] $_ +} + +constant @euler = (^∞).map: &euler; + +sub is-perfect-totient ($n) { + $n == sum @euler[$n], { @euler[$_] } ... 1 +} + +multi MAIN (Bool :test($)!) { + use Test; + is is-perfect-totient(4375), True; + is is-perfect-totient(5571), True; + is is-perfect-totient(729), True; + is is-perfect-totient(739),False; + done-testing; +} + +multi MAIN ($k=20) { + 3,5...∞ + andthen .grep: &is-perfect-totient + andthen .head: $k + andthen .Supply + andthen .tap: *.put +} -- cgit