From 4327afa48b21b27bf30cbcd3f2a659a3588b0024 Mon Sep 17 00:00:00 2001 From: Flavio Poletti Date: Wed, 27 Jul 2022 06:03:30 +0200 Subject: Add polettix's solution to challenge-175 --- challenge-175/polettix/blog.txt | 1 + challenge-175/polettix/blog1.txt | 1 + challenge-175/polettix/perl/ch-1.pl | 39 ++ challenge-175/polettix/perl/ch-2.pl | 73 ++ challenge-175/polettix/perl/cpanfile | 2 + challenge-175/polettix/perl/cpanfile.snapshot | 916 ++++++++++++++++++++++++++ challenge-175/polettix/raku/ch-1.raku | 27 + challenge-175/polettix/raku/ch-2.raku | 66 ++ 8 files changed, 1125 insertions(+) create mode 100644 challenge-175/polettix/blog.txt create mode 100644 challenge-175/polettix/blog1.txt create mode 100644 challenge-175/polettix/perl/ch-1.pl create mode 100644 challenge-175/polettix/perl/ch-2.pl create mode 100644 challenge-175/polettix/perl/cpanfile create mode 100644 challenge-175/polettix/perl/cpanfile.snapshot create mode 100644 challenge-175/polettix/raku/ch-1.raku create mode 100644 challenge-175/polettix/raku/ch-2.raku diff --git a/challenge-175/polettix/blog.txt b/challenge-175/polettix/blog.txt new file mode 100644 index 0000000000..ef9e9d8c61 --- /dev/null +++ b/challenge-175/polettix/blog.txt @@ -0,0 +1 @@ +https://etoobusy.polettix.it/2022/07/27/pwc175-last-sunday/ diff --git a/challenge-175/polettix/blog1.txt b/challenge-175/polettix/blog1.txt new file mode 100644 index 0000000000..9facb9ea1d --- /dev/null +++ b/challenge-175/polettix/blog1.txt @@ -0,0 +1 @@ +https://etoobusy.polettix.it/2022/07/28/pwc175-perfect-totient-numbers/ diff --git a/challenge-175/polettix/perl/ch-1.pl b/challenge-175/polettix/perl/ch-1.pl new file mode 100644 index 0000000000..361f54bca7 --- /dev/null +++ b/challenge-175/polettix/perl/ch-1.pl @@ -0,0 +1,39 @@ +#!/usr/bin/env perl +use v5.24; +use warnings; +use experimental 'signatures'; +no warnings 'experimental::signatures'; + +use DateTime; + +my $year = shift // 2022; +say for sundays_in($year); + +sub sundays_in ($year) { + my $year_start = DateTime->new( + year => $year, + month => 1, + day => 1, + hour => 12, + time_zone => 'floating', + ); + + # find the first sunday in the year + my $cursor = $year_start->clone; + $cursor->add(days => 1) while $cursor->day_of_week % 7; + + # find all last sundays in the year + my @retval; + while ($cursor->year == $year) { + + # we will compare a candidate sunday against the next one + my $candidate = $cursor->clone; + $cursor->add(days => 7); + + # a jump in the month for the "next" sunday means that our + # $candidate was the last one in its month, so take it + push @retval, $candidate->ymd('-') + if $cursor->month != $candidate->month; + } + return @retval; +} diff --git a/challenge-175/polettix/perl/ch-2.pl b/challenge-175/polettix/perl/ch-2.pl new file mode 100644 index 0000000000..6f86fcf4ad --- /dev/null +++ b/challenge-175/polettix/perl/ch-2.pl @@ -0,0 +1,73 @@ +#!/usr/bin/env perl +use v5.24; +use warnings; +use experimental 'signatures'; +no warnings 'experimental::signatures'; + +use ntheory 'euler_phi'; + +my $n_items = shift // 20; +say + for BruteCheck::brutechecker( + iterator => BruteCheck::int_iterator('2..'), + ender => BruteCheck::max_size($n_items), + checker => sub ($n) { return totient_supersum($n) == $n }, + ); + +sub totient_supersum ($n) { + state $cache = {0 => 0, 1 => 1, 2 => 1}; + + # first "recurse" up to the point where we have something + # in cache + my @stack = $n; + push @stack, $n = euler_phi($n) while ! exists $cache->{$n}; + + # then go back down to calculate all new needed values + $n = pop @stack; + my $pred = $cache->{$n}; + while (@stack) { + ($n, my $phi) = (pop(@stack), $n); + $pred = $cache->{$n} = $phi + $pred; + } + + # whatever is left is what we were after in the first place + return $pred; +} + +package BruteCheck; + +sub max_size ($n) { sub ($aref) { $aref->@* >= $n } } + +sub int_iterator ($spec) { + my ($start, $stop, $step) = $spec =~ m{ + \A + ([1-9]\d*|0|) + \.\. + ([1-9]\d*|0|) + (?: / (-?[1-9]\d*))? + \z + }mxs; + $start ||= 0; + $step ||= 1; + + my $i = $start; + return sub { + return + if length($stop) + && (($step > 0 && $i > $stop) || ($step < 0 && $i < $stop)); + my $retval = $i; + $i += $step; + return $retval; + }; +} ## end sub int_iterator ($spec) + +sub brutechecker (%args) { + my ($checker, $iterator, $ender) = @args{qw< checker iterator ender >}; + $iterator //= int_iterator('..'); + $ender //= sub { 0 }; + my @retval; + while (!$ender->(\@retval) && defined(my $candidate = $iterator->())) { + push @retval, $candidate if $checker->($candidate); + } + return @retval; +} ## end sub brutechecker (%args) diff --git a/challenge-175/polettix/perl/cpanfile b/challenge-175/polettix/perl/cpanfile new file mode 100644 index 0000000000..cb85d24eb2 --- /dev/null +++ b/challenge-175/polettix/perl/cpanfile @@ -0,0 +1,2 @@ +requires 'DateTime'; +requires 'ntheory'; diff --git a/challenge-175/polettix/perl/cpanfile.snapshot b/challenge-175/polettix/perl/cpanfile.snapshot new file mode 100644 index 0000000000..ffb175b923 --- /dev/null +++ b/challenge-175/polettix/perl/cpanfile.snapshot @@ -0,0 +1,916 @@ +# carton snapshot format: version 1.0 +DISTRIBUTIONS + B-Hooks-EndOfScope-0.26 + pathname: E/ET/ETHER/B-Hooks-EndOfScope-0.26.tar.gz + provides: + B::Hooks::EndOfScope 0.26 + B::Hooks::EndOfScope::PP 0.26 + B::Hooks::EndOfScope::XS 0.26 + requirements: + ExtUtils::MakeMaker 0 + Hash::Util::FieldHash 0 + Module::Implementation 0.05 + Scalar::Util 0 + Sub::Exporter::Progressive 0.001006 + Text::ParseWords 0 + Tie::Hash 0 + Variable::Magic 0.48 + perl 5.006001 + strict 0 + warnings 0 + Class-Data-Inheritable-0.09 + pathname: R/RS/RSHERER/Class-Data-Inheritable-0.09.tar.gz + provides: + Class::Data::Inheritable 0.09 + requirements: + ExtUtils::MakeMaker 0 + Class-Inspector-1.36 + pathname: P/PL/PLICEASE/Class-Inspector-1.36.tar.gz + provides: + Class::Inspector 1.36 + Class::Inspector::Functions 1.36 + requirements: + ExtUtils::MakeMaker 0 + File::Spec 0.80 + base 0 + perl 5.008 + Class-Singleton-1.6 + pathname: S/SH/SHAY/Class-Singleton-1.6.tar.gz + provides: + Class::Singleton 1.6 + requirements: + ExtUtils::MakeMaker 6.64 + perl 5.008001 + strict 0 + warnings 0 + DateTime-1.58 + pathname: D/DR/DROLSKY/DateTime-1.58.tar.gz + provides: + DateTime 1.58 + DateTime::Duration 1.58 + DateTime::Helpers 1.58 + DateTime::Infinite 1.58 + DateTime::Infinite::Future 1.58 + DateTime::Infinite::Past 1.58 + DateTime::LeapSecond 1.58 + DateTime::PP 1.58 + DateTime::PPExtra 1.58 + DateTime::Types 1.58 + requirements: + Carp 0 + DateTime::Locale 1.06 + DateTime::TimeZone 2.44 + Dist::CheckConflicts 0.02 + ExtUtils::MakeMaker 0 + POSIX 0 + Params::ValidationCompiler 0.26 + Scalar::Util 0 + Specio 0.18 + Specio::Declare 0 + Specio::Exporter 0 + Specio::Library::Builtins 0 + Specio::Library::Numeric 0 + Specio::Library::String 0 + Specio::Subs 0 + Try::Tiny 0 + XSLoader 0 + base 0 + integer 0 + namespace::autoclean 0.19 + overload 0 + parent 0 + perl 5.008004 + strict 0 + warnings 0 + warnings::register 0 + DateTime-Locale-1.35 + pathname: D/DR/DROLSKY/DateTime-Locale-1.35.tar.gz + provides: + DateTime::Locale 1.35 + DateTime::Locale::Base 1.35 + DateTime::Locale::Catalog 1.35 + DateTime::Locale::Data 1.35 + DateTime::Locale::FromData 1.35 + DateTime::Locale::Util 1.35 + requirements: + Carp 0 + Dist::CheckConflicts 0.02 + Exporter 0 + ExtUtils::MakeMaker 0 + File::ShareDir 0 + File::ShareDir::Install 0.06 + File::Spec 0 + List::Util 1.45 + Params::ValidationCompiler 0.13 + Specio::Declare 0 + Specio::Library::String 0 + Storable 0 + namespace::autoclean 0.19 + perl 5.008004 + strict 0 + warnings 0 + DateTime-TimeZone-2.52 + pathname: D/DR/DROLSKY/DateTime-TimeZone-2.52.tar.gz + provides: + DateTime::TimeZone 2.52 + DateTime::TimeZone::Africa::Abidjan 2.52 + DateTime::TimeZone::Africa::Algiers 2.52 + DateTime::TimeZone::Africa::Bissau 2.52 + DateTime::TimeZone::Africa::Cairo 2.52 + DateTime::TimeZone::Africa::Casablanca 2.52 + DateTime::TimeZone::Africa::Ceuta 2.52 + DateTime::TimeZone::Africa::El_Aaiun 2.52 + DateTime::TimeZone::Africa::Johannesburg 2.52 + DateTime::TimeZone::Africa::Juba 2.52 + DateTime::TimeZone::Africa::Khartoum 2.52 + DateTime::TimeZone::Africa::Lagos 2.52 + DateTime::TimeZone::Africa::Maputo 2.52 + DateTime::TimeZone::Africa::Monrovia 2.52 + DateTime::TimeZone::Africa::Nairobi 2.52 + DateTime::TimeZone::Africa::Ndjamena 2.52 + DateTime::TimeZone::Africa::Sao_Tome 2.52 + DateTime::TimeZone::Africa::Tripoli 2.52 + DateTime::TimeZone::Africa::Tunis 2.52 + DateTime::TimeZone::Africa::Windhoek 2.52 + DateTime::TimeZone::America::Adak 2.52 + DateTime::TimeZone::America::Anchorage 2.52 + DateTime::TimeZone::America::Araguaina 2.52 + DateTime::TimeZone::America::Argentina::Buenos_Aires 2.52 + DateTime::TimeZone::America::Argentina::Catamarca 2.52 + DateTime::TimeZone::America::Argentina::Cordoba 2.52 + DateTime::TimeZone::America::Argentina::Jujuy 2.52 + DateTime::TimeZone::America::Argentina::La_Rioja 2.52 + DateTime::TimeZone::America::Argentina::Mendoza 2.52 + DateTime::TimeZone::America::Argentina::Rio_Gallegos 2.52 + DateTime::TimeZone::America::Argentina::Salta 2.52 + DateTime::TimeZone::America::Argentina::San_Juan 2.52 + DateTime::TimeZone::America::Argentina::San_Luis 2.52 + DateTime::TimeZone::America::Argentina::Tucuman 2.52 + DateTime::TimeZone::America::Argentina::Ushuaia 2.52 + DateTime::TimeZone::America::Asuncion 2.52 + DateTime::TimeZone::America::Bahia 2.52 + DateTime::TimeZone::America::Bahia_Banderas 2.52 + DateTime::TimeZone::America::Barbados 2.52 + DateTime::TimeZone::America::Belem 2.52 + DateTime::TimeZone::America::Belize 2.52 + DateTime::TimeZone::America::Boa_Vista 2.52 + DateTime::TimeZone::America::Bogota 2.52 + DateTime::TimeZone::America::Boise 2.52 + DateTime::TimeZone::America::Cambridge_Bay 2.52 + DateTime::TimeZone::America::Campo_Grande 2.52 + DateTime::TimeZone::America::Cancun 2.52 + DateTime::TimeZone::America::Caracas 2.52 + DateTime::TimeZone::America::Cayenne 2.52 + DateTime::TimeZone::America::Chicago 2.52 + DateTime::TimeZone::America::Chihuahua 2.52 + DateTime::TimeZone::America::Costa_Rica 2.52 + DateTime::TimeZone::America::Cuiaba 2.52 + DateTime::TimeZone::America::Danmarkshavn 2.52 + DateTime::TimeZone::America::Dawson 2.52 + DateTime::TimeZone::America::Dawson_Creek 2.52 + DateTime::TimeZone::America::Denver 2.52 + DateTime::TimeZone::America::Detroit 2.52 + DateTime::TimeZone::America::Edmonton 2.52 + DateTime::TimeZone::America::Eirunepe 2.52 + DateTime::TimeZone::America::El_Salvador 2.52 + DateTime::TimeZone::America::Fort_Nelson 2.52 + DateTime::TimeZone::America::Fortaleza 2.52 + DateTime::TimeZone::America::Glace_Bay 2.52 + DateTime::TimeZone::America::Goose_Bay 2.52 + DateTime::TimeZone::America::Grand_Turk 2.52 + DateTime::TimeZone::America::Guatemala 2.52 + DateTime::TimeZone::America::Guayaquil 2.52 + DateTime::TimeZone::America::Guyana 2.52 + DateTime::TimeZone::America::Halifax 2.52 + DateTime::TimeZone::America::Havana 2.52 + DateTime::TimeZone::America::Hermosillo 2.52 + DateTime::TimeZone::America::Indiana::Indianapolis 2.52 + DateTime::TimeZone::America::Indiana::Knox 2.52 + DateTime::TimeZone::America::Indiana::Marengo 2.52 + DateTime::TimeZone::America::Indiana::Petersburg 2.52 + DateTime::TimeZone::America::Indiana::Tell_City 2.52 + DateTime::TimeZone::America::Indiana::Vevay 2.52 + DateTime::TimeZone::America::Indiana::Vincennes 2.52 + DateTime::TimeZone::America::Indiana::Winamac 2.52 + DateTime::TimeZone::America::Inuvik 2.52 + DateTime::TimeZone::America::Iqaluit 2.52 + DateTime::TimeZone::America::Jamaica 2.52 + DateTime::TimeZone::America::Juneau 2.52 + DateTime::TimeZone::America::Kentucky::Louisville 2.52 + DateTime::TimeZone::America::Kentucky::Monticello 2.52 + DateTime::TimeZone::America::La_Paz 2.52 + DateTime::TimeZone::America::Lima 2.52 + DateTime::TimeZone::America::Los_Angeles 2.52 + DateTime::TimeZone::America::Maceio 2.52 + DateTime::TimeZone::America::Managua 2.52 + DateTime::TimeZone::America::Manaus 2.52 + DateTime::TimeZone::America::Martinique 2.52 + DateTime::TimeZone::America::Matamoros 2.52 + DateTime::TimeZone::America::Mazatlan 2.52 + DateTime::TimeZone::America::Menominee 2.52 + DateTime::TimeZone::America::Merida 2.52 + DateTime::TimeZone::America::Metlakatla 2.52 + DateTime::TimeZone::America::Mexico_City 2.52 + DateTime::TimeZone::America::Miquelon 2.52 + DateTime::TimeZone::America::Moncton 2.52 + DateTime::TimeZone::America::Monterrey 2.52 + DateTime::TimeZone::America::Montevideo 2.52 + DateTime::TimeZone::America::New_York 2.52 + DateTime::TimeZone::America::Nipigon 2.52 + DateTime::TimeZone::America::Nome 2.52 + DateTime::TimeZone::America::Noronha 2.52 + DateTime::TimeZone::America::North_Dakota::Beulah 2.52 + DateTime::TimeZone::America::North_Dakota::Center 2.52 + DateTime::TimeZone::America::North_Dakota::New_Salem 2.52 + DateTime::TimeZone::America::Nuuk 2.52 + DateTime::TimeZone::America::Ojinaga 2.52 + DateTime::TimeZone::America::Panama 2.52 + DateTime::TimeZone::America::Pangnirtung 2.52 + DateTime::TimeZone::America::Paramaribo 2.52 + DateTime::TimeZone::America::Phoenix 2.52 + DateTime::TimeZone::America::Port_au_Prince 2.52 + DateTime::TimeZone::America::Porto_Velho 2.52 + DateTime::TimeZone::America::Puerto_Rico 2.52 + DateTime::TimeZone::America::Punta_Arenas 2.52 + DateTime::TimeZone::America::Rainy_River 2.52 + DateTime::TimeZone::America::Rankin_Inlet 2.52 + DateTime::TimeZone::America::Recife 2.52 + DateTime::TimeZone::America::Regina 2.52 + DateTime::TimeZone::America::Resolute 2.52 + DateTime::TimeZone::America::Rio_Branco 2.52 + DateTime::TimeZone::America::Santarem 2.52 + DateTime::TimeZone::America::Santiago 2.52 + DateTime::TimeZone::America::Santo_Domingo 2.52 + DateTime::TimeZone::America::Sao_Paulo 2.52 + DateTime::TimeZone::America::Scoresbysund 2.52 + DateTime::TimeZone::America::Sitka 2.52 + DateTime::TimeZone::America::St_Johns 2.52 + DateTime::TimeZone::America::Swift_Current 2.52 + DateTime::TimeZone::America::Tegucigalpa 2.52 + DateTime::TimeZone::America::Thule 2.52 + DateTime::TimeZone::America::Thunder_Bay 2.52 + DateTime::TimeZone::America::Tijuana 2.52 + DateTime::TimeZone::America::Toronto 2.52 + DateTime::TimeZone::America::Vancouver 2.52 + DateTime::TimeZone::America::Whitehorse 2.52 + DateTime::TimeZone::America::Winnipeg 2.52 + DateTime::TimeZone::America::Yakutat 2.52 + DateTime::TimeZone::America::Yellowknife 2.52 + DateTime::TimeZone::Antarctica::Casey 2.52 + DateTime::TimeZone::Antarctica::Davis 2.52 + DateTime::TimeZone::Antarctica::Macquarie 2.52 + DateTime::TimeZone::Antarctica::Mawson 2.52 + DateTime::TimeZone::Antarctica::Palmer 2.52 + DateTime::TimeZone::Antarctica::Rothera 2.52 + DateTime::TimeZone::Antarctica::Troll 2.52 + DateTime::TimeZone::Antarctica::Vostok 2.52 + DateTime::TimeZone::Asia::Almaty 2.52 + DateTime::TimeZone::Asia::Amman 2.52 + DateTime::TimeZone::Asia::Anadyr 2.52 + DateTime::TimeZone::Asia::Aqtau 2.52 + DateTime::TimeZone::Asia::Aqtobe 2.52 + DateTime::TimeZone::Asia::Ashgabat 2.52 + DateTime::TimeZone::Asia::Atyrau 2.52 + DateTime::TimeZone::Asia::Baghdad 2.52 + DateTime::TimeZone::Asia::Baku 2.52 + DateTime::TimeZone::Asia::Bangkok 2.52 + DateTime::TimeZone::Asia::Barnaul 2.52 + DateTime::TimeZone::Asia::Beirut 2.52 + DateTime::TimeZone::Asia::Bishkek 2.52 + DateTime::TimeZone::Asia::Brunei 2.52 + DateTime::TimeZone::Asia::Chita 2.52 + DateTime::TimeZone::Asia::Choibalsan 2.52 + DateTime::TimeZone::Asia::Colombo 2.52 + DateTime::TimeZone::Asia::Damascus 2.52 + DateTime::TimeZone::Asia::Dhaka 2.52 + DateTime::TimeZone::Asia::Dili 2.52 + DateTime::TimeZone::Asia::Dubai 2.52 + DateTime::TimeZone::Asia::Dushanbe 2.52 + DateTime::TimeZone::Asia::Famagusta 2.52 + DateTime::TimeZone::Asia::Gaza 2.52 + DateTime::TimeZone::Asia::Hebron 2.52 + DateTime::TimeZone::Asia::Ho_Chi_Minh 2.52 + DateTime::TimeZone::Asia::Hong_Kong 2.52 + DateTime::TimeZone::Asia::Hovd 2.52 + DateTime::TimeZone::Asia::Irkutsk 2.52 + DateTime::TimeZone::Asia::Jakarta 2.52 + DateTime::TimeZone::Asia::Jayapura 2.52 + DateTime::TimeZone::Asia::Jerusalem 2.52 + DateTime::TimeZone::Asia::Kabul 2.52 + DateTime::TimeZone::Asia::Kamchatka 2.52 + DateTime::TimeZone::Asia::Karachi 2.52 + DateTime::TimeZone::Asia::Kathmandu 2.52 + DateTime::TimeZone::Asia::Khandyga 2.52 + DateTime::TimeZone::Asia::Kolkata 2.52 + DateTime::TimeZone::Asia::Krasnoyarsk 2.52 + DateTime::TimeZone::Asia::Kuala_Lumpur 2.52 + DateTime::TimeZone::Asia::Kuching 2.52 + DateTime::TimeZone::Asia::Macau 2.52 + DateTime::TimeZone::Asia::Magadan 2.52 + DateTime::TimeZone::Asia::Makassar 2.52 + DateTime::TimeZone::Asia::Manila 2.52 + DateTime::TimeZone::Asia::Nicosia 2.52 + DateTime::TimeZone::Asia::Novokuznetsk 2.52 + DateTime::TimeZone::Asia::Novosibirsk 2.52 + DateTime::TimeZone::Asia::Omsk 2.52 + DateTime::TimeZone::Asia::Oral 2.52 + DateTime::TimeZone::Asia::Pontianak 2.52 + DateTime::TimeZone::Asia::Pyongyang 2.52 + DateTime::TimeZone::Asia::Qatar 2.52 + DateTime::TimeZone::Asia::Qostanay 2.52 + DateTime::TimeZone::Asia::Qyzylorda 2.52 + DateTime::TimeZone::Asia::Riyadh 2.52 + DateTime::TimeZone::Asia::Sakhalin 2.52 + DateTime::TimeZone::Asia::Samarkand 2.52 + DateTime::TimeZone::Asia::Seoul 2.52 + DateTime::TimeZone::Asia::Shanghai 2.52 + DateTime::TimeZone::Asia::Singapore 2.52 + DateTime::TimeZone::Asia::Srednekolymsk 2.52 + DateTime::TimeZone::Asia::Taipei 2.52 + DateTime::TimeZone::Asia::Tashkent 2.52 + DateTime::TimeZone::Asia::Tbilisi 2.52 + DateTime::TimeZone::Asia::Tehran 2.52 + DateTime::TimeZone::Asia::Thimphu 2.52 + DateTime::TimeZone::Asia::Tokyo 2.52 + DateTime::TimeZone::Asia::Tomsk 2.52 + DateTime::TimeZone::Asia::Ulaanbaatar 2.52 + DateTime::TimeZone::Asia::Urumqi 2.52 + DateTime::TimeZone::Asia::Ust_Nera 2.52 + DateTime::TimeZone::Asia::Vladivostok 2.52 + DateTime::TimeZone::Asia::Yakutsk 2.52 + DateTime::TimeZone::Asia::Yangon 2.52 + DateTime::TimeZone::Asia::Yekaterinburg 2.52 + DateTime::TimeZone::Asia::Yerevan 2.52 + DateTime::TimeZone::Atlantic::Azores 2.52 + DateTime::TimeZone::Atlantic::Bermuda 2.52 + DateTime::TimeZone::Atlantic::Canary 2.52 + DateTime::TimeZone::Atlantic::Cape_Verde 2.52 + DateTime::TimeZone::Atlantic::Faroe 2.52 + DateTime::TimeZone::Atlantic::Madeira 2.52 + DateTime::TimeZone::Atlantic::Reykjavik 2.52 + DateTime::TimeZone::Atlantic::South_Georgia 2.52 + DateTime::TimeZone::Atlantic::Stanley 2.52 + DateTime::TimeZone::Australia::Adelaide 2.52 + DateTime::TimeZone::Australia::Brisbane 2.52 + DateTime::TimeZone::Australia::Broken_Hill 2.52 + DateTime::TimeZone::Australia::Darwin 2.52 + DateTime::TimeZone::Australia::Eucla 2.52 + DateTime::TimeZone::Australia::Hobart 2.52 + DateTime::TimeZone::Australia::Lindeman 2.52 + DateTime::TimeZone::Australia::Lord_Howe 2.52 + DateTime::TimeZone::Australia::Melbourne 2.52 + DateTime::TimeZone::Australia::Perth 2.52 + DateTime::TimeZone::Australia::Sydney 2.52 + DateTime::TimeZone::CET 2.52 + DateTime::TimeZone::CST6CDT 2.52 + DateTime::TimeZone::Catalog 2.52 + DateTime::TimeZone::EET 2.52 + DateTime::TimeZone::EST 2.52 + DateTime::TimeZone::EST5EDT 2.52 + DateTime::TimeZone::Europe::Amsterdam 2.52 + DateTime::TimeZone::Europe::Andorra 2.52 + DateTime::TimeZone::Europe::Astrakhan 2.52 + DateTime::TimeZone::Europe::Athens 2.52 + DateTime::TimeZone::Europe::Belgrade 2.52 + DateTime::TimeZone::Europe::Berlin 2.52 + DateTime::TimeZone::Europe::Brussels 2.52 + DateTime::TimeZone::Europe::Bucharest 2.52 + DateTime::TimeZone::Europe::Budapest 2.52 + DateTime::TimeZone::Europe::Chisinau 2.52 + DateTime::TimeZone::Europe::Copenhagen 2.52 + DateTime::TimeZone::Europe::Dublin 2.52 + DateTime::TimeZone::Europe::Gibraltar 2.52 + DateTime::TimeZone::Europe::Helsinki 2.52 + DateTime::TimeZone::Europe::Istanbul 2.52 + DateTime::TimeZone::Europe::Kaliningrad 2.52 + DateTime::TimeZone::Europe::Kiev 2.52 + DateTime::TimeZone::Europe::Kirov 2.52 + DateTime::TimeZone::Europe::Lisbon 2.52 + DateTime::TimeZone::Europe::London 2.52 + DateTime::TimeZone::Europe::Luxembourg 2.52 + DateTime::TimeZone::Europe::Madrid 2.52 + DateTime::TimeZone::Europe::Malta 2.52 + DateTime::TimeZone::Europe::Minsk 2.52 + DateTime::TimeZone::Europe::Monaco 2.52 + DateTime::TimeZone::Europe::Moscow 2.52 + DateTime::TimeZone::Europe::Oslo 2.52 + DateTime::TimeZone::Europe::Paris 2.52 + DateTime::TimeZone::Europe::Prague 2.52 + DateTime::TimeZone::Europe::Riga 2.52 + DateTime::TimeZone::Europe::Rome 2.52 + DateTime::TimeZone::Europe::Samara 2.52 + DateTime::TimeZone::Europe::Saratov 2.52 + DateTime::TimeZone::Europe::Simferopol 2.52 + DateTime::TimeZone::Europe::Sofia 2.52 + DateTime::TimeZone::Europe::Stockholm 2.52 + DateTime::TimeZone::Europe::Tallinn 2.52 + DateTime::TimeZone::Europe::Tirane 2.52 + DateTime::TimeZone::Europe::Ulyanovsk 2.52 + DateTime::TimeZone::Europe::Uzhgorod 2.52 + DateTime::TimeZone::Europe::Vienna 2.52 + DateTime::TimeZone::Europe::Vilnius 2.52 + DateTime::TimeZone::Europe::Volgograd 2.52 + DateTime::TimeZone::Europe::Warsaw 2.52 + DateTime::TimeZone::Europe::Zaporozhye 2.52 + DateTime::TimeZone::Europe::Zurich 2.52 + DateTime::TimeZone::Floating 2.52 + DateTime::TimeZone::HST 2.52 + DateTime::TimeZone::Indian::Chagos 2.52 + DateTime::TimeZone::Indian::Christmas 2.52 + DateTime::TimeZone::Indian::Cocos 2.52 + DateTime::TimeZone::Indian::Kerguelen 2.52 + DateTime::TimeZone::Indian::Mahe 2.52 + DateTime::TimeZone::Indian::Maldives 2.52 + DateTime::TimeZone::Indian::Mauritius 2.52 + DateTime::TimeZone::Indian::Reunion 2.52 + DateTime::TimeZone::Local 2.52 + DateTime::TimeZone::Local::Android 2.52 + DateTime::TimeZone::Local::Unix 2.52 + DateTime::TimeZone::Local::VMS 2.52 + DateTime::TimeZone::MET 2.52 + DateTime::TimeZone::MST 2.52 + DateTime::TimeZone::MST7MDT 2.52 + DateTime::TimeZone::OffsetOnly 2.52 + DateTime::TimeZone::OlsonDB 2.52 + DateTime::TimeZone::OlsonDB::Change 2.52 + DateTime::TimeZone::OlsonDB::Observance 2.52 + DateTime::TimeZone::OlsonDB::Rule 2.52 + DateTime::TimeZone::OlsonDB::Zone 2.52 + DateTime::TimeZone::PST8PDT 2.52 + DateTime::TimeZone::Pacific::Apia 2.52 + DateTime::TimeZone::Pacific::Auckland 2.52 + DateTime::TimeZone::Pacific::Bougainville 2.52 + DateTime::TimeZone::Pacific::Chatham 2.52 + DateTime::TimeZone::Pacific::Chuuk 2.52 + DateTime::TimeZone::Pacific::Easter 2.52 + DateTime::TimeZone::Pacific::Efate 2.52 + DateTime::TimeZone::Pacific::Fakaofo 2.52 + DateTime::TimeZone::Pacific::Fiji 2.52 + DateTime::TimeZone::Pacific::Funafuti 2.52 + DateTime::TimeZone::Pacific::Galapagos 2.52 + DateTime::TimeZone::Pacific::Gambier 2.52 + DateTime::TimeZone::Pacific::Guadalcanal 2.52 + DateTime::TimeZone::Pacific::Guam 2.52 + DateTime::TimeZone::Pacific::Honolulu 2.52 + DateTime::TimeZone::Pacific::Kanton 2.52 + DateTime::TimeZone::Pacific::Kiritimati 2.52 + DateTime::TimeZone::Pacific::Kosrae 2.52 + DateTime::TimeZone::Pacific::Kwajalein 2.52 + DateTime::TimeZone::Pacific::Majuro 2.52 + DateTime::TimeZone::Pacific::Marquesas 2.52 + DateTime::TimeZone::Pacific::Nauru 2.52 + DateTime::TimeZone::Pacific::Niue 2.52 + DateTime::TimeZone::Pacific::Norfolk 2.52 + DateTime::TimeZone::Pacific::Noumea 2.52 + DateTime::TimeZone::Pacific::Pago_Pago 2.52 + DateTime::TimeZone::Pacific::Palau 2.52 + DateTime::TimeZone::Pacific::Pitcairn 2.52 + DateTime::TimeZone::Pacific::Pohnpei 2.52 + DateTime::TimeZone::Pacific::Port_Moresby 2.52 + DateTime::TimeZone::Pacific::Rarotonga 2.52 + DateTime::TimeZone::Pacific::Tahiti 2.52 + DateTime::TimeZone::Pacific::Tarawa 2.52 + DateTime::TimeZone::Pacific::Tongatapu 2.52 + DateTime::TimeZone::Pacific::Wake 2.52 + DateTime::TimeZone::Pacific::Wallis 2.52 + DateTime::TimeZone::UTC 2.52 + DateTime::TimeZone::WET 2.52 + requirements: + Class::Singleton 1.03 + Cwd 3 + ExtUtils::MakeMaker 0 + File::Basename 0 + File::Compare 0 + File::Find 0 + File::Spec 0 + List::Util 1.33 + Module::Runtime 0 + Params::ValidationCompiler 0.13 + Specio::Library::Builtins 0 + Specio::Library::String 0 + Try::Tiny 0 + constant 0 + namespace::autoclean 0 + parent 0 + perl 5.008004 + strict 0 + warnings 0 + Devel-StackTrace-2.04 + pathname: D/DR/DROLSKY/Devel-StackTrace-2.04.tar.gz + provides: + Devel::StackTrace 2.04 + Devel::StackTrace::Frame 2.04 + requirements: + ExtUtils::MakeMaker 0 + File::Spec 0 + Scalar::Util 0 + overload 0 + perl 5.006 + strict 0 + warnings 0 + Dist-CheckConflicts-0.11 + pathname: D/DO/DOY/Dist-CheckConflicts-0.11.tar.gz + provides: + Dist::CheckConflicts 0.11 + requirements: + Carp 0 + Exporter 0 + ExtUtils::MakeMaker 6.30 + Module::Runtime 0.009 + base 0 + strict 0 + warnings 0 + Eval-Closure-0.14 + pathname: D/DO/DOY/Eval-Closure-0.14.tar.gz + provides: + Eval::Closure 0.14 + requirements: + Carp 0 + Exporter 0 + ExtUtils::MakeMaker 0 + Scalar::Util 0 + constant 0 + overload 0 + strict 0 + warnings 0 + Exception-Class-1.45 + pathname: D/DR/DROLSKY/Exception-Class-1.45.tar.gz + provides: + Exception::Class 1.45 + Exception::Class::Base 1.45 + requirements: + Carp 0 + Class::Data::Inheritable 0.02 + Devel::StackTrace 2.00 + ExtUtils::MakeMaker 0 + Scalar::Util 0 + base 0 + overload 0 + perl 5.008001 + strict 0 + warnings 0 + File-ShareDir-1.118 + pathname: R/RE/REHSACK/File-ShareDir-1.118.tar.gz + provides: + File::ShareDir 1.118 + requirements: + Carp 0 + Class::Inspector 1.12 + ExtUtils::MakeMaker 0 + File::ShareDir::Install 0.13 + File::Spec 0.80 + perl 5.008001 + warnings 0 + File-ShareDir-Install-0.14 + pathname: E/ET/ETHER/File-ShareDir-Install-0.14.tar.gz + provides: + File::ShareDir::Install 0.14 + requirements: + Carp 0 + Exporter 0 + ExtUtils::MakeMaker 0 + File::Spec 0 + IO::Dir 0 + perl 5.006 + strict 0 + warnings 0 + MRO-Compat-0.15 + pathname: H/HA/HAARG/MRO-Compat-0.15.tar.gz + provides: + MRO::Compat 0.15 + requirements: + ExtUtils::MakeMaker 0 + perl 5.006 + Math-Prime-Util-0.73 + pathname: D/DA/DANAJ/Math-Prime-Util-0.73.tar.gz + provides: + Math::Prime::Util 0.73 + Math::Prime::Util::ChaCha 0.73 + Math::Prime::Util::Entropy 0.73 + Math::Prime::Util::MemFree 0.73 + Math::Prime::Util::PP 0.73 + Math::Prime::Util::PrimeArray 0.73 + Math::Prime::Util::PrimeIterator 0.73 + ntheory 0.73 + requirements: + Carp 0 + Config 0 + Exporter 5.57 + ExtUtils::MakeMaker 0 + Math::BigFloat 1.59 + Math::BigInt 1.88 + Math::Prime::Util::GMP 0.50 + Tie::Array 0 + XSLoader 0.01 + base 0 + constant 0 + perl 5.006002 + Math-Prime-Util-GMP-0.52 + pathname: D/DA/DANAJ/Math-Prime-Util-GMP-0.52.tar.gz + provides: + Math::Prime::Util::GMP 0.52 + requirements: + Carp 0 + Exporter 5.57 + ExtUtils::MakeMaker 0 + Fcntl 0 + XSLoader 0.01 + base 0 + perl 5.006002 + Module-Build-0.4231 + pathname: L/LE/LEONT/Module-Build-0.4231.tar.gz + provides: + Module::Build 0.4231 + Module::Build::Base 0.4231 + Module::Build::Compat 0.4231 + Module::Build::Config 0.4231 + Module::Build::Cookbook 0.4231 + Module::Build::Dumper 0.4231 + Module::Build::Notes 0.4231 + Module::Build::PPMMaker 0.4231 + Module::Build::Platform::Default 0.4231 + Module::Build::Platform::MacOS 0.4231 + Module::Build::Platform::Unix 0.4231 + Module::Build::Platform::VMS 0.4231 + Module::Build::Platform::VOS 0.4231 + Module::Build::Platform::Windows 0.4231 + Module::Build::Platform::aix 0.4231 + Module::Build::Platform::cygwin 0.4231 + Module::Build::Platform::darwin 0.4231 + Module::Build::Platform::os2 0.4231 + Module::Build::PodParser 0.4231 + requirements: + CPAN::Meta 2.142060 + Cwd 0 + Data::Dumper 0 + ExtUtils::CBuilder 0.27 + ExtUtils::Install 0 + ExtUtils::Manifest 0 + ExtUtils::Mkbootstrap 0 + ExtUtils::ParseXS 2.21 + File::Basename 0 + File::Compare 0 + File::Copy 0 + File::Find 0 + File::Path 0 + File::Spec 0.82 + Getopt::Long 0 + Module::Metadata 1.000002 + Perl::OSType 1 + Pod::Man 2.17 + TAP::Harness 3.29 + Text::Abbrev 0 + Text::ParseWords 0 + perl 5.006001 + version 0.87 + Module-Implementation-0.09 + pathname: D/DR/DROLSKY/Module-Implementation-0.09.tar.gz + provides: + Module::Implementation 0.09 + requirements: + Carp 0 + ExtUtils::MakeMaker 0 + Module::Runtime 0.012 + Try::Tiny 0 + strict 0 + warnings 0 + Module-Runtime-0.016 + pathname: Z/ZE/ZEFRAM/Module-Runtime-0.016.tar.gz + provides: + Module::Runtime 0.016 + requirements: + Module::Build 0 + Test::More 0.41 + perl 5.006 + strict 0 + warnings 0 + Package-Stash-0.40 + pathname: E/ET/ETHER/Package-Stash-0.40.tar.gz + provides: + Package::Stash 0.40 + Package::Stash::PP 0.40 + requirements: + B 0 + Carp 0 + Dist::CheckConflicts 0.02 + ExtUtils::MakeMaker 0 + Getopt::Long 0 + Module::Implementation 0.06 + Package::Stash::XS 0.26 + Scalar::Util 0 + Symbol 0 + Text::ParseWords 0 + constant 0 + perl 5.008001 + strict 0 + warnings 0 + Package-Stash-XS-0.30 + pathname: E/ET/ETHER/Package-Stash-XS-0.30.tar.gz + provides: + Package::Stash::XS 0.30 + requirements: + ExtUtils::MakeMaker 0 + XSLoader 0 + perl 5.008001 + strict 0 + warnings 0 + Params-ValidationCompiler-0.30 + pathname: D/DR/DROLSKY/Params-ValidationCompiler-0.30.tar.gz + provides: + Params::ValidationCompiler 0.30 + Params::ValidationCompiler::Compiler 0.30 + Params::ValidationCompiler::Exceptions 0.30 + requirements: + B 0 + Carp 0 + Eval::Closure 0 + Exception::Class 0 + Exporter 0 + ExtUtils::MakeMaker 0 + List::Util 1.29 + Scalar::Util 0 + overload 0 + strict 0 + warnings 0 + Role-Tiny-2.002004 + pathname: H/HA/HAARG/Role-Tiny-2.002004.tar.gz + provides: + Role::Tiny 2.002004 + Role::Tiny::With 2.002004 + requirements: + Exporter 5.57 + perl 5.006 + Scalar-List-Utils-1.62 + pathname: P/PE/PEVANS/Scalar-List-Utils-1.62.tar.gz + provides: + List::Util 1.62 + List::Util::XS 1.62 + Scalar::Util 1.62 + Sub::Util 1.62 + requirements: + ExtUtils::MakeMaker 0 + perl 5.006 + Specio-0.48 + pathname: D/DR/DROLSKY/Specio-0.48.tar.gz + provides: + Specio 0.48 + Specio::Coercion 0.48 + Specio::Constraint::AnyCan 0.48 + Specio::Constraint::AnyDoes 0.48 + Specio::Constraint::AnyIsa 0.48 + Specio::Constraint::Enum 0.48 + Specio::Constraint::Intersection 0.48 + Specio::Constraint::ObjectCan 0.48 + Specio::Constraint::ObjectDoes 0.48 + Specio::Constraint::ObjectIsa 0.48 + Specio::Constraint::Parameterizable 0.48 + Specio::Constraint::Parameterized 0.48 + Specio::Constraint::Role::CanType 0.48 + Specio::Constraint::Role::DoesType 0.48 + Specio::Constraint::Role::Interface 0.48 + Specio::Constraint::Role::IsaType 0.48 + Specio::Constraint::Simple 0.48 + Specio::Constraint::Structurable 0.48 + Specio::Constraint::Structured 0.48 + Specio::Constraint::Union 0.48 + Specio::Declare 0.48 + Specio::DeclaredAt 0.48 + Specio::Exception 0.48 + Specio::Exporter 0.48 + Specio::Helpers 0.48 + Specio::Library::Builtins 0.48 + Specio::Library::Numeric 0.48 + Specio::Library::Perl 0.48 + Specio::Library::String 0.48 + Specio::Library::Structured 0.48 + Specio::Library::Structured::Dict 0.48 + Specio::Library::Structured::Map 0.48 + Specio::Library::Structured::Tuple 0.48 + Specio::OO 0.48 + Specio::PartialDump 0.48 + Specio::Registry 0.48 + Specio::Role::Inlinable 0.48 + Specio::Subs 0.48 + Specio::TypeChecks 0.48 + Test::Specio 0.48 + requirements: + B 0 + Carp 0 + Devel::StackTrace 0 + Eval::Closure 0 + Exporter 0 + ExtUtils::MakeMaker 0 + IO::File 0 + List::Util 1.33 + MRO::Compat 0 + Module::Runtime 0 + Role::Tiny 1.003003 + Role::Tiny::With 0 + Scalar::Util 0 + Storable 0 + Sub::Quote 0 + Test::Fatal 0 + Test::More 0.96 + Try::Tiny 0 + XString 0 + overload 0 + parent 0 + perl 5.008 + re 0 + strict 0 + version 0.83 + warnings 0 + Sub-Exporter-Progressive-0.001013 + pathname: F/FR/FREW/Sub-Exporter-Progressive-0.001013.tar.gz + provides: + Sub::Exporter::Progressive 0.001013 + requirements: + ExtUtils::MakeMaker 0 + Sub-Identify-0.14 + pathname: R/RG/RGARCIA/Sub-Identify-0.14.tar.gz + provides: + Sub::Identify 0.14 + requirements: + ExtUtils::MakeMaker 0 + Test::More 0 + Sub-Quote-2.006006 + pathname: H/HA/HAARG/Sub-Quote-2.006006.tar.gz + provides: + Sub::Defer 2.006006 + Sub::Quote 2.006006 + requirements: + ExtUtils::MakeMaker 0 + Scalar::Util 0 + perl 5.006 + Test-Fatal-0.016 + pathname: R/RJ/RJBS/Test-Fatal-0.016.tar.gz + provides: + Test::Fatal 0.016 + requirements: + Carp 0 + Exporter 5.57 + ExtUtils::MakeMaker 0 + Test::Builder 0 + Try::Tiny 0.07 + strict 0 + warnings 0 + Try-Tiny-0.31 + pathname: E/ET/ETHER/Try-Tiny-0.31.tar.gz + provides: + Try::Tiny 0.31 + requirements: + Carp 0 + Exporter 5.57 + ExtUtils::MakeMaker 0 + constant 0 + perl 5.006 + strict 0 + warnings 0 + Variable-Magic-0.62 + pathname: V/VP/VPIT/Variable-Magic-0.62.tar.gz + provides: + Variable::Magic 0.62 + requirements: + Carp 0 + Config 0 + Exporter 0 + ExtUtils::MakeMaker 0 + IO::Handle 0 + IO::Select 0 + IPC::Open3 0 + POSIX 0 + Socket 0 + Test::More 0 + XSLoader 0 + base 0 + lib 0 + perl 5.008 + XString-0.005 + pathname: A/AT/ATOOMIC/XString-0.005.tar.gz + provides: + XString 0.005 + requirements: + ExtUtils::MakeMaker 0 + perl 5.008 + namespace-autoclean-0.29 + pathname: E/ET/ETHER/namespace-autoclean-0.29.tar.gz + provides: + namespace::autoclean 0.29 + requirements: + B::Hooks::EndOfScope 0.12 + ExtUtils::MakeMaker 0 + List::Util 0 + Sub::Identify 0 + namespace::clean 0.20 + perl 5.006 + strict 0 + warnings 0 + namespace-clean-0.27 + pathname: R/RI/RIBASUSHI/namespace-clean-0.27.tar.gz + provides: + namespace::clean 0.27 + requirements: + B::Hooks::EndOfScope 0.12 + ExtUtils::MakeMaker 0 + Package::Stash 0.23 + perl 5.008001 diff --git a/challenge-175/polettix/raku/ch-1.raku b/challenge-175/polettix/raku/ch-1.raku new file mode 100644 index 0000000000..53534c9b61 --- /dev/null +++ b/challenge-175/polettix/raku/ch-1.raku @@ -0,0 +1,27 @@ +#!/usr/bin/env raku +use v6; +sub MAIN (Int:D $year = 2022) { .put for sundays-in($year) } + +sub sundays-in (Int:D $year) { + my $year-start = Date.new(:$year); + + # find the first sunday in the year + my $cursor = $year-start; + $cursor++ while $cursor.day-of-week % 7; + + # find all last sundays in the year + return gather loop { + + # we will compare a candidate sunday against the next one + my $candidate = $cursor; + $cursor += 7; + + # a jump in the month for the "next" sunday means that our + # $candidate was the last one in its month, so take it + take $candidate if $cursor.month != $candidate.month; + + # a jump in the year means we've taken the last one in the + # requested year, so we can just say goodbye + last if $cursor.year > $candidate.year; + }; +} diff --git a/challenge-175/polettix/raku/ch-2.raku b/challenge-175/polettix/raku/ch-2.raku new file mode 100644 index 0000000000..c73a0c0e7d --- /dev/null +++ b/challenge-175/polettix/raku/ch-2.raku @@ -0,0 +1,66 @@ +#!/usr/bin/env raku +use v6; + +class IntIterator { ... } +class BruteCheck { ... } +sub MAIN (Int:D $n where * > 0 = 20) { + $*OUT.out-buffer = False; + .put for BruteCheck.new( + iterator => IntIterator.new(start => 2), + ender => -> @x { @x.elems == $n }, + checker => sub ($n) { $n == totient-supersum($n) }, + ).run(); +} + +sub totient-supersum ($n is copy) { + state %cache = <0 0 1 1 2 1>; + + my @stack = $n,; + @stack.push($n = euler-phi($n)) while %cache{$n}:!exists; + + $n = @stack.pop; + my $pred = %cache{$n}; + while @stack { + ($n, my $phi) = @stack.pop, $n; + $pred = %cache{$n} = $phi + $pred; + } + + return $pred; +} + +sub euler-phi ($n) { + state %cache = <0 0 1 1 2 1>; + return %cache{$n} //= (1 ..^ $n).grep({($_ gcd $n) == 1}).elems; +} + +class IntIterator { + has $.start is readonly is built = 0; + has $.stop is readonly is built = Inf; + has $.step is readonly is built = 1; + has $!current; + submethod TWEAK() { + $!current = $!start; + $!stop = -Inf if $!stop == Inf && $!step < 0; + } + method pull-one { + return Nil + if ($!step > 0 && $!current > $!stop) + || ($!step < 0 && $!current < $!stop); + my $retval = $!current; + $!current += $!step; + return $retval; + } +}; + +class BruteCheck { + has &.checker; + has &.ender is built = sub (@r) { False }; + has $.iterator is built = IntIterator.new(); + method run { + my @rval; + while (! &!ender(@rval) && defined(my $c = $!iterator.pull-one())) { + @rval.push: $c if &!checker($c); + } + return @rval; + } +} -- cgit