aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2022-07-31 13:22:17 +0100
committerGitHub <noreply@github.com>2022-07-31 13:22:17 +0100
commit01a929b47a9878a64b876b7314aa206d221905b1 (patch)
tree60d7298756c11143c11962f84c8741b67a56a5ef
parentc2c36138889fbbc355458720abca4f08384a95a0 (diff)
parent12f99e0e18d7770a7028f4fad05f37ea0562f589 (diff)
downloadperlweeklychallenge-club-01a929b47a9878a64b876b7314aa206d221905b1.tar.gz
perlweeklychallenge-club-01a929b47a9878a64b876b7314aa206d221905b1.tar.bz2
perlweeklychallenge-club-01a929b47a9878a64b876b7314aa206d221905b1.zip
Merge pull request #6526 from wambash/challenge-week-175
Challenge week 175
-rw-r--r--challenge-175/wambash/julia/ch-1.jl11
-rw-r--r--challenge-175/wambash/julia/ch-2.jl10
-rw-r--r--challenge-175/wambash/raku/ch-1.raku32
-rw-r--r--challenge-175/wambash/raku/ch-2.raku33
4 files changed, 86 insertions, 0 deletions
diff --git a/challenge-175/wambash/julia/ch-1.jl b/challenge-175/wambash/julia/ch-1.jl
new file mode 100644
index 0000000000..79c76f60d2
--- /dev/null
+++ b/challenge-175/wambash/julia/ch-1.jl
@@ -0,0 +1,11 @@
+using Lazy
+using Dates
+
+year = isassigned(ARGS) ? parse(Int,ARGS[1]) : 2022
+
+@>> 1:12 begin
+ map( m -> @lazy lastdayofmonth( Date(year,m)):Day(-1):Date(year,m) )
+ map( m -> filter( d -> dayofweek(d) == 7, m ) )
+ map(first)
+ foreach(println)
+end
diff --git a/challenge-175/wambash/julia/ch-2.jl b/challenge-175/wambash/julia/ch-2.jl
new file mode 100644
index 0000000000..2703b5dc7b
--- /dev/null
+++ b/challenge-175/wambash/julia/ch-2.jl
@@ -0,0 +1,10 @@
+#!/usr/bin/env julia
+
+using Primes
+using Lazy
+
+totientsum(x) = @>> x iterated(totient) takeuntil( ==(1) ) drop(1) sum
+
+k = isassigned(ARGS) ? parse(Int,ARGS[1]) : 20
+
+@>> Lazy.range(3,Inf,2) filter( x -> totientsum(x) == x) take(k) collect println
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
+}