Perl Weekly Challenge 69: Strobogrammatic Numbers and 0/1 Strings

These are some answers to the Week 69 of the Perl Weekly Challenge organized by Mohammad S. Anwar.

Spoiler Alert: This weekly challenge deadline is due in a couple of days (July 19, 2020). This blog post offers some solutions to this challenge, please don’t read on if you intend to complete the challenge on your own.

Task 1: Strobogrammatic Numbers

A strobogrammatic number is a number that looks the same when looked at upside down.

You are given two positive numbers $A and $B such that 1 <= $A <= $B <= 10^15.

Write a script to print all strobogrammatic numbers between the given two numbers.

Example

Input: $A = 50, $B = 100
Output: 69, 88, 96

Paws XXXXIX (Very Close)

Finally things were looking my way. I plowed thought the remaining CloudFront actions and got them all to work without any more changes to Paws.

In the end I checked in 30+ new tests cases and over 2k of tests the other day. So I can safely say that 'CloudFront' is fully operational.

That leaves only 'Route53' to look and for me this is somewhat problematic. The Route53 api deals with 'Domains', 'Checks', 'Hosts', 'Traffic' and such. To test 90% of the actions in this API you will need

  1. Have at least one registered DNS domains to start
  2. Know how to create a Hosts for a Domain
  3. Know how to config a Host for a Domain and most importantly
  4. Have some spare cash to pay for all the actions you are mucking with

As I fail on all 4 of the above I am not comfortable with creating working scrips for this API.

Springtime in Switzerland

For over a decade now, I've been running public training classes in both presentation skills
and software development in conjunction with the Swiss Institute of Bioinformatics,
the University of Lausanne, and the École Polytechnique Fédérale de Lausanne.

This year, in the week of March 9-13, we're offering my full set of Presentation Skills classes as a three-day sequence (though, of course, you can also sign up for just one or two of the classes, if you prefer):

We’re also offering two general software development classes:

These two classes are based on my popular Perl courses on these topics, but I've now
redesigned and adapted them to be entirely language-neutral, so they're equally useful
to developers working in any other mainstream language(s).

Docker, Perl and GitHub

Why using Docker images?

There are many reasons to use Docker Images, from setting up a development environment to pushing your code to production. The primary/first reason which pushes me to start using some Docker Images is "Continuous Integration".

When maintaining a Perl package used by multiple users/companies (or not), you absolutely want to know how your code behaves on different versions of Perl. Even if you could have multiple versions of Perl installed on your development environment, most of the time, the development is only performed using a single version of Perl.

Continuous Integration system like Travis CI or GitHub Workflows allows you to run your test suite on every push, pull request... without the need of testing manually on all Perl Versions.

When testing your code on a container (or Virtual Machine) you do not want to install or compile a fresh version of Perl each time... This is a slow operation, that ideally, should be done once.

# Perl Weekly Challenge 68: Zero Matrix

These are some answers to the Week 68 of the Perl Weekly Challenge organized by Mohammad S. Anwar.

Task 1: Zero Matrix

You are given a matrix of size M x N having only 0s and 1s.

Write a script to set the entire row and column to 0 if an element is 0.

Example 1:

Input: [1, 0, 1]
       [1, 1, 1]
       [1, 1, 1]

Output: [0, 0, 0]
        [1, 0, 1]
        [1, 0, 1]

Example 2:

Shorewall 5.2.3.5 Released!

Shorewall 5.2.3.5 is now available for download. Shorewall is a gateway/firewall configuration tool for GNU/Linux, written in Perl.

Problems Corrected:

1) A typo in the FTP documentation has been corrected.

2) The recommended mss setting when using IPSec with ipcomp
has been corrected.

3) A number of incorrect links in the manpages have been
corrected.

4) The 'bypass' option is now allowed when specifying an
NFQUEUE policy. Previously, specifying that option resulted
in an error.

5) Corrected IPv6 Address Range parsing.

Previously, such ranges were required to be of the form
[-] rather than the more standard form
[]-[]. In the snat file (and in nat actions),
the latter form was actually flagged as an error while in
other contexts, it resulted in a less obvious error being
raised.

6) The manpages have been updated to refer to https://shorewall.org rather than http://www.shorewall.org.

Call for FOSDEM 2020 Booth volunteers

This year we've got one of the high-traffic locations, on the ground floor where Free Software Foundation Europe set up last year, right next to the stairway to *all* the dev rooms. So we're looking for volunteers to come and talk about both Perl and Raku at FOSDEM 2020 in Brussels. If I haven't already talked to you, please email me at drforr [at] pobox (dot) com and give me an idea of your availability and what you'd want to do. We've made arrangements for the usual booth swag, and will have pamphlets to hand out and books to sell on both Raku and Perl.

Again, if you're able to give us a hand or know someone that can, send me email at drforr [at] pobox (dot) com and give me an idea of when you're available and how much you can help out.

Perl Weekly Challenge 043: Olympic Rings and Self-Descriptive Numbers

Olympic Rings

There are 5 rings in the Olympic Logo [as shown below]. They are colour coded as in Blue, Black, Red, Yellow and Green. We have allocated some numbers to these rings as below: Blue: 8, Yellow: 7, Green: 5, Red: 9. The Black ring is empty currently. You are given the numbers 1, 2, 3, 4 and 6. Write a script to place these numbers in the rings so that the sum of numbers in each ring is exactly 11.

My first idea was to go over all the possible permutation of the numbers and report those that satisfy the sum condition. I chose Math::Combinatorics as the module to handle the permutations.

Perl Weekly Challenge 67: Number Combinations and Letter Phone

These are some answers to the Week 67 of the Perl Weekly Challenge organized by Mohammad S. Anwar.

Spoiler Alert: This weekly challenge deadline is due in a couple of days (July 5, 2020). This blog post offers some solutions to this challenge, please don’t read on if you intend to complete the challenge on your own.

Task 1: Number Combinations

You are given two integers $m and $n. Write a script print all possible combinations of $n numbers from the list 1 2 3 … $m.

Every combination should be sorted i.e. [2,3] is valid combination but [3,2] is not.

Example:

Input: $m = 5, $n = 2

Output: [ [1,2], [1,3], [1,4], [1,5], [2,3], [2,4], [2,5], [3,4], [3,5], [4,5] ]

Note that I don’t consider the formatting of the displayed output above to be part of the task.

Number Combinations in Raku

Create PDF using Perl/PDF::API2

I wrote a practical and detailed description of Perl's PDF::API2.

It turns out that PDF::API2 is a library for performing necessary and sufficient PDF operations.

Create PDF using Perl/PDF::API2

Paws XXXXVIII (Way too many 'I' s)

Well I think it is a first here in the Paws patrol. I spent the day plunging away with CloudFront and I have no new Paws issues but I did learn and important practical lesson about using CloudFront.

I got stuck on the 'UpdateCloudFrontOriginAccessIdentity' call.

It seemed simple enough


$s3->UpdateCloudFrontOriginAccessIdentity(
    CloudFrontOriginAccessIdentityConfig => {
        CallerReference => 'Some text here',
        Comment         => 'Mr Pooppy buthole did this',
  },
  Id=> 'E3D5Y5RWA05QO1',
);

but I kept running into this error;

The request failed because it didn't meet the preconditions in one or more request-header fields.

Ok what is that?

A Date with CPAN, Update #3: Golden Jubilee

[This is an addendum post to a series.  You may want to begin at the beginning.  The last update was update #2.

IMPORTANT NOTE! When I provide you links to code on GitHub, I’m giving you links to particular commits.  This allows me to show you the code as it was at the time the blog post was written and insures that the code references will make sense in the context of this post.  Just be aware that the latest version of the code may be very different.]


In case you missed my talk on Date::Easy from a couple years back, I’ll sum it up for you: dates are hard, y’all.

Perl Weekly Challenge 66: Divide Integers and Power Integers

These are some answers to the Week 66 of the Perl Weekly Challenge organized by Mohammad S. Anwar.

Task 1: Divide Integers

You are given two integers $M and $N.

Write a script to divide the given two integers i.e. $M / $N without using multiplication, division and mod operator and return the floor of the result of the division.

Example 1:

Input: $M = 5, $N = 2
Output: 2

Example 2:

Input: $M = -5, $N = 2
Output: -3

Example 3:

Input: $M = -5, $N = -2
Output: 2

No more rhyming and I k-means it!

"... anybody wanna peanut?" - Fezzik, TPB

When last we saw our heroes, they had just applied PDL::Stats::Kmeans to a CSV file of car data with no thought regarding their own well-being.

In today's episode, we see them slice through data to identify clusters of cars, only to find they know less than they did before!

Read on, true believers!

Paws XXXXVI (The game she is over)

Well I left off on form my last post with this Moose error;

Attribute (Items) does not pass the type constraint because: Validation failed for 'ArrayRef[Str|Undef]' with value [ { Method: ARRAY(0x5184cf0) } ] at /wwwveh/lib/x86_64-linux-thread-multi/Moose/Object.pm line 24

but before I tackle that on I wanted to have a closer look at my changes I did to the callresult_class.tt template; I wanted to clean that up nicely and then my plan is to see if my changes have Borden anything else.

So in cleaning it up I found what might be a bug.

It seems that this call


[%- IF (stream_param or shape.payload == param_name) %]

is now out of the attributes foreach loop so I change things about a bit and now I just set a var in the template and apply the new trait if the var has a value;

Modern functions in a post-modern language

Update: Time::Local 1.30 includes a new pair of functions timegm_posix/timelocal_posix which address all issues outlined in this article, including the issues with the traditional functions, at least as pertains to Time::Local’s purpose as an inverse of the gmtime/localtime Perl builtins.

The new _modern function variants in Time::Local have come up a few times lately. I have some thoughts on them, but presenting my position dispassionately enough to be persuasive demands an essay of unfortunate length… so let’s get on with it.

Let me lead with the positive: it is a problem with the traditional functions that they would sometimes add 1900 to the year and sometimes a different value and sometimes nothing. This heuristic in the interface is bad. Doing something about it is a good idea.

Perl Weekly Challenge 65: Digit Sum

These are some answers to the Week 65 of the Perl Weekly Challenge organized by Mohammad S. Anwar.

You are given two positive numbers $N and $S.

Write a script to list all positive numbers having exactly $N digits where sum of all digits equals to $S.

Example:

Input:
    $N = 2
    $S = 4

Output:
    13, 22, 31, 40

Digit Sum in Raku

My first attempt to solve the problem would be a pure brute force approach as follows:

My Y2020 Bug

For reasons that must have been clear at the time, I once wrote a test in terms of epoch time, and wanted it to run on systems that did not use January 1 1970 as the epoch. So I loaded Time::Local and added timegm( 0, 0, 0, 1, 0, 70 ) to the desired epoch.

This morning I got a CPAN testers report failure. It seems that if you give timegm() a year in the range 0-99 it assumes it is within 50 years of the current year, so my test suddenly thought the epoch was 2070.

In this case, the obvious response is to specify a four-digit year.

Maybe a better response is to ditch timegm() and timelocal() completely in favor of timegm_modern() and timelocal_modern(). These require Time::Local version 1.27, released June 2019. According to its metadata it works back to Perl 5.6, though so far I have only verified it back to Perl 5.8.1.

With thanks to Dave Rolsky for the *_modern() variants, and to Chris Williams (BINGOS), who uncovered this in one of his CPAN tester systems.

CPAN Testers Rule!

Paws XXXXVII (What about the tests????)

I decided I might as well get busy with CloudFront and at least get most of my real world scripts written.

At the moment I am getting 400 errors such as 'InvalidArgument' or 'InvalidOrigin' on the Delete and Create actions as I do not have the proper config on the AWS end for the Creates and for the Deletes as I do not have anything on my AWS account to delete.

Reading though the API documentation is seems there is quite the procedure to actually do some of the actions, for example to invoke the DeleteStreamingDistribution action you have to follow a six pre-steps all of which must pass. So I guess I can forget a quick run on this API

So the plan is to get all the real world scripts written up and then go though the full CRUD actions for each and get them working with a good generated test case for each.

Class, Role And Attribute Accessor in Raku

Quite ingenious title I used here, but it's precise. This story starts with the following case:

role R {
    method a { 666 }
}
class C does R {
    has $.a = 42;
}
say C.new.a;


What would you expect this to print?

For those with basic or no knowledge in Raku I'd like to explain that a public attribute gets an automatic accessor method. So, when one does $obj.attribute it's actually a method call.

There could be some disagreement among devs wether the code should output 42 or 666. Though Raku states it explicitly that things defined by class have priority over role's declared ones. Hence, we expect 42 here.

Period, this post is over, everybody is free to go? Alas, this issue says that the code above outputs 666! Oops... What's going on here?

About blogs.perl.org

blogs.perl.org is a common blogging platform for the Perl community. Written in Perl with a graphic design donated by Six Apart, Ltd.