aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2021-03-05 07:00:31 +0000
committerGitHub <noreply@github.com>2021-03-05 07:00:31 +0000
commit73c7fc27b38535dc60e672baa3fa9b411abc4659 (patch)
treea03b147544e5d4773bc01cc1953e9c1ee60fec27
parentf760cbd9ef69aa1f075404aa5f6dc3e151a8bec0 (diff)
parent63df156fb7a57c8eb2c29c9b19f89794ac0a96b7 (diff)
downloadperlweeklychallenge-club-73c7fc27b38535dc60e672baa3fa9b411abc4659.tar.gz
perlweeklychallenge-club-73c7fc27b38535dc60e672baa3fa9b411abc4659.tar.bz2
perlweeklychallenge-club-73c7fc27b38535dc60e672baa3fa9b411abc4659.zip
Merge pull request #3660 from polettix/polettix/pwc102
Add polettix's solution to PWC102
-rw-r--r--challenge-102/polettix/blog.txt1
-rw-r--r--challenge-102/polettix/blog1.txt1
-rw-r--r--challenge-102/polettix/cpanfile1
-rw-r--r--challenge-102/polettix/cpanfile.snapshot120
-rw-r--r--challenge-102/polettix/perl/ch-1.pl46
-rw-r--r--challenge-102/polettix/perl/ch-2.pl14
6 files changed, 183 insertions, 0 deletions
diff --git a/challenge-102/polettix/blog.txt b/challenge-102/polettix/blog.txt
new file mode 100644
index 0000000000..afb6e10e87
--- /dev/null
+++ b/challenge-102/polettix/blog.txt
@@ -0,0 +1 @@
+https://github.polettix.it/ETOOBUSY/2021/03/03/pwc102-rare-numbers/
diff --git a/challenge-102/polettix/blog1.txt b/challenge-102/polettix/blog1.txt
new file mode 100644
index 0000000000..12b86c4caa
--- /dev/null
+++ b/challenge-102/polettix/blog1.txt
@@ -0,0 +1 @@
+https://github.polettix.it/ETOOBUSY/2021/03/04/pwc102-hash-counting-string/
diff --git a/challenge-102/polettix/cpanfile b/challenge-102/polettix/cpanfile
new file mode 100644
index 0000000000..e0ff2998b7
--- /dev/null
+++ b/challenge-102/polettix/cpanfile
@@ -0,0 +1 @@
+requires 'Mojo::UserAgent';
diff --git a/challenge-102/polettix/cpanfile.snapshot b/challenge-102/polettix/cpanfile.snapshot
new file mode 100644
index 0000000000..88881cc63d
--- /dev/null
+++ b/challenge-102/polettix/cpanfile.snapshot
@@ -0,0 +1,120 @@
+# carton snapshot format: version 1.0
+DISTRIBUTIONS
+ Mojolicious-9.02
+ pathname: S/SR/SRI/Mojolicious-9.02.tar.gz
+ provides:
+ Mojo undef
+ Mojo::Asset undef
+ Mojo::Asset::File undef
+ Mojo::Asset::Memory undef
+ Mojo::Base undef
+ Mojo::ByteStream undef
+ Mojo::Cache undef
+ Mojo::Collection undef
+ Mojo::Content undef
+ Mojo::Content::MultiPart undef
+ Mojo::Content::Single undef
+ Mojo::Cookie undef
+ Mojo::Cookie::Request undef
+ Mojo::Cookie::Response undef
+ Mojo::DOM undef
+ Mojo::DOM::CSS undef
+ Mojo::DOM::HTML undef
+ Mojo::Date undef
+ Mojo::DynamicMethods undef
+ Mojo::EventEmitter undef
+ Mojo::Exception undef
+ Mojo::File undef
+ Mojo::Headers undef
+ Mojo::HelloWorld undef
+ Mojo::Home undef
+ Mojo::IOLoop undef
+ Mojo::IOLoop::Client undef
+ Mojo::IOLoop::Server undef
+ Mojo::IOLoop::Stream undef
+ Mojo::IOLoop::Subprocess undef
+ Mojo::IOLoop::TLS undef
+ Mojo::JSON undef
+ Mojo::JSON::Pointer undef
+ Mojo::Loader undef
+ Mojo::Log undef
+ Mojo::Message undef
+ Mojo::Message::Request undef
+ Mojo::Message::Response undef
+ Mojo::Parameters undef
+ Mojo::Path undef
+ Mojo::Promise undef
+ Mojo::Reactor undef
+ Mojo::Reactor::EV undef
+ Mojo::Reactor::Poll undef
+ Mojo::Server undef
+ Mojo::Server::CGI undef
+ Mojo::Server::Daemon undef
+ Mojo::Server::Hypnotoad undef
+ Mojo::Server::Morbo undef
+ Mojo::Server::Morbo::Backend undef
+ Mojo::Server::Morbo::Backend::Poll undef
+ Mojo::Server::PSGI undef
+ Mojo::Server::Prefork undef
+ Mojo::Template undef
+ Mojo::Transaction undef
+ Mojo::Transaction::HTTP undef
+ Mojo::Transaction::WebSocket undef
+ Mojo::URL undef
+ Mojo::Upload undef
+ Mojo::UserAgent undef
+ Mojo::UserAgent::CookieJar undef
+ Mojo::UserAgent::Proxy undef
+ Mojo::UserAgent::Server undef
+ Mojo::UserAgent::Transactor undef
+ Mojo::Util undef
+ Mojo::WebSocket undef
+ Mojolicious 9.02
+ Mojolicious::Command undef
+ Mojolicious::Command::Author::cpanify undef
+ Mojolicious::Command::Author::generate undef
+ Mojolicious::Command::Author::generate::app undef
+ Mojolicious::Command::Author::generate::dockerfile undef
+ Mojolicious::Command::Author::generate::lite_app undef
+ Mojolicious::Command::Author::generate::makefile undef
+ Mojolicious::Command::Author::generate::plugin undef
+ Mojolicious::Command::Author::inflate undef
+ Mojolicious::Command::cgi undef
+ Mojolicious::Command::daemon undef
+ Mojolicious::Command::eval undef
+ Mojolicious::Command::get undef
+ Mojolicious::Command::prefork undef
+ Mojolicious::Command::psgi undef
+ Mojolicious::Command::routes undef
+ Mojolicious::Command::version undef
+ Mojolicious::Commands undef
+ Mojolicious::Controller undef
+ Mojolicious::Lite undef
+ Mojolicious::Plugin undef
+ Mojolicious::Plugin::Config undef
+ Mojolicious::Plugin::DefaultHelpers undef
+ Mojolicious::Plugin::EPLRenderer undef
+ Mojolicious::Plugin::EPRenderer undef
+ Mojolicious::Plugin::HeaderCondition undef
+ Mojolicious::Plugin::JSONConfig undef
+ Mojolicious::Plugin::Mount undef
+ Mojolicious::Plugin::NotYAMLConfig undef
+ Mojolicious::Plugin::TagHelpers undef
+ Mojolicious::Plugins undef
+ Mojolicious::Renderer undef
+ Mojolicious::Routes undef
+ Mojolicious::Routes::Match undef
+ Mojolicious::Routes::Pattern undef
+ Mojolicious::Routes::Route undef
+ Mojolicious::Sessions undef
+ Mojolicious::Static undef
+ Mojolicious::Types undef
+ Mojolicious::Validator undef
+ Mojolicious::Validator::Validation undef
+ Test::Mojo undef
+ ojo undef
+ requirements:
+ ExtUtils::MakeMaker 0
+ IO::Socket::IP 0.37
+ Sub::Util 1.41
+ perl 5.016
diff --git a/challenge-102/polettix/perl/ch-1.pl b/challenge-102/polettix/perl/ch-1.pl
new file mode 100644
index 0000000000..416dd48622
--- /dev/null
+++ b/challenge-102/polettix/perl/ch-1.pl
@@ -0,0 +1,46 @@
+#!/usr/bin/env perl
+use 5.024;
+use warnings;
+use experimental qw< postderef signatures >;
+no warnings qw< experimental::postderef experimental::signatures >;
+
+use FindBin '$Bin';
+use lib "$Bin/../local/lib/perl5";
+use Mojo::UserAgent;
+
+my $digits = shift || 10;
+my $rn = rare_numbers($digits);
+
+my $title = ($digits == 1) ? '1 digit:' : "$digits digits:";
+say $title, ' ', join ', ', $rn->@*;
+
+sub rare_numbers ($N) {
+ my ($ml, $retval) = get_rare_numbers_for($N, get_rn_cache());
+ return $retval if $N <= $ml;
+ ($ml, $retval) = get_rare_numbers_for($N, get_rn_web());
+ return $retval if $N <= $ml;
+ die "carbon footprint too high, sorry!\n";
+}
+
+sub get_rare_numbers_for ($N, $list) {
+ my @retval;
+ my $max_length = 0;
+ for my $item ($list->@*) {
+ my $len = length $item;
+ $max_length = $len if $len > $max_length;
+ last if $max_length > $N;
+ push @retval, $item if $len == $N;
+ }
+ return ($max_length, \@retval);
+}
+
+sub get_rn_web {
+ my $ua = Mojo::UserAgent->new(connect_timeout => 5, max_redirects => 5);
+ my $res = $ua->get('http://oeis.org/A035519/b035519.txt')->res;
+ die "web is not collaborating, sorry!\n" unless $res->is_success;
+ return [
+ map { my ($i, $n) = split m{\s+}; $n } split m{\n}mxs, $res->body
+ ];
+}
+
+sub get_rn_cache { [ 65, 621770, 281089082, 2022652202, 2042832002 ] }
diff --git a/challenge-102/polettix/perl/ch-2.pl b/challenge-102/polettix/perl/ch-2.pl
new file mode 100644
index 0000000000..4f9405b57a
--- /dev/null
+++ b/challenge-102/polettix/perl/ch-2.pl
@@ -0,0 +1,14 @@
+#!/usr/bin/env perl
+use 5.024;
+use warnings;
+use experimental qw< postderef signatures >;
+no warnings qw< experimental::postderef experimental::signatures >;
+
+sub hash_counting_string ($N) {
+ my $retval = '';
+ ($retval, $N) = ("$N#$retval", $N - 1 - length $N) while $N > 1;
+ return $N == 1 ? "#$retval" : $retval;
+}
+
+my $n = shift || 10;
+say hash_counting_string($n);