Perl Weekly Challenge 54: k-th Permutation Sequence and the Collatz Conjecture

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

Spoiler Alert: This weekly challenge deadline is due in a couple of days (April 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: kth Permutation Sequence

Write a script to accept two integers n (>=1) and k (>=1). It should print the kth permutation of n integers. For more information, please follow the wiki page.

For example, n=3 and k=4, the possible permutation sequences are listed below:

Paws XXXXI (Doubble Sawbuck plus 1)

I was hoping that I would have an easy time with S3Control once I figured out the XML problems. Sadly I was a little premature on that thought.

I spent a good while over the past few days getting either an 'Access Denied' or 'Forbidden' response to my 'CreateJob' call.

I eventually though that I might as well try one of the simpler calls and get that working and then work may way up. So I tried the simplest of all;

It's beginning to look a lot like k-Means 🎵

... every where you go!

Continuing on from the intention of clustering data in Perl (a form of unsupervised learning), I'm going to start with PDL::Stats::Kmeans and see how far I can get.

Let's just plunge in and use the module and read the documentation after to figure out what it all k-means. (sorry)

The way that CPAN authors use subroutine signatures in natural

Perl's new feature is for the new Perl, but when it comes to subroutine signatures, CPAN Author also maybe wants to use it.

If CPAN authors can use subroutine signatures, both application code and CPAN module code can be written in one source.

I think new features should work with the new Perl, but I'm happy that only the subroutine signature feature can be backported.

Wouldn't it be nice if you could use subroutine signatures with tens of thousands of CPAN modules?

But is there such a way?

The way that CPAN authors use subroutine signatures in natural

Perl Weekly Challenge 53: Rotate Matrix and Vowel Strings

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

Spoiler Alert: This weekly challenge deadline is due in a couple of days (March 29, 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: Rotate Matrix

Write a script to rotate the following matrix by given 90/180/270 degrees clockwise.

[ 1, 2, 3 ]
[ 4, 5, 6 ]
[ 7, 8, 9 ]

For example, if you rotate by 90 degrees then expected result should be like below:

[ 7, 4, 1 ]
[ 8, 5, 2 ]
[ 9, 6, 3 ]

Long time no see

Paws XXXVII (So close but yest so far)

Well I was just about ready to check everything in on S3 Paws and move onto the next part of Paws that need some love and kindness when I did one last review of all the test cases I have created over the past little while when I discovered I had left one out.

I forgot to add in a request test case for the 'DeleteBucketMetricsConfiguration' action. It took the opportunity to use my new test generator a spin as well so I fired up my real world call with the new caller and much to my chagrin I got an error;

'The specified configuration does not exist.',

Which could be the case as the Bucket I was playing with may not have a 'Metrics Configuration' on it. So I dusted off another test that does both 'PUT and 'GET' and then I slapped my 'DELETE' on the end and this was the result;

Is the new grammar easy to google search?

Is the new grammar of subroutine signatures easy to google search?

One of the criticisms of Perl is that "it cannot search google because it has many symbols".

Increasing the number of difficult-to-search symbols also increases the blame for Perl.

Is the new grammar easy to google search?

Perl Weekly Challenge 52: Stepping Numbers and Lucky Winner

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

Task 1: Stepping Numbers

Write a script to accept two numbers between 100 and 999. It should then print all Stepping Numbers between them.

A number is called a stepping number if the adjacent digits have a difference of 1. For example, 456 is a stepping number but 129 is not.

Just to make things slightly clearer, I would say that all adjacent digits should have an absolute difference of 1, so that 542, 454, or 654 are also stepping numbers.

Stepping Numbers in Perl

Given that the range is quite small, we can use a brute force approach on all numbers between the input values: check for every number in the range whether it fits the definition.

Can't post a comment here -- dunno why

Why, oh why, can't I post a comment on blogs.perl.org? I'm properly signed in. I read a post, 30 seconds later. 30 seconds later, I click the button at the bottom of the post in order to post a reply. I fill in the form with my post. Then I get this error:

---

Comment Submission Error

Your comment submission failed for the following reasons: Your session has expired. Please sign in again to comment.

Return to the original entry.

---

And there is no avoiding it, even after signing in again.

Thanks very much for any help you can provide.

Rewriting Perl Code for Raku Part V is out

Part V of the series is out, this time more in-depth discussions of the pack() method in Raku and Perl

New Role Of Roles In Raku

My morning started today with a cup of cold tea and an IRC request. The latter was coming from Elizabeth Mattijsen asking to write a paragraph on my recently merged work on Raku roles. There was a little problem though: I have no idea how to fit it into a single paragraph! And so I was left with no choice but to start blogging for the first time in many years.

Note. For those of you who consider themselves Raku experts I'd rather recommend skipping the next two sections and proceed directly to the technical details in Changes.

Once upon a time...

... there was a project which I was implementing to support a my boss' project. The structure of the code was heavily based on roles. This is the pattern I tend to use: split functionality into manageable as small as possible pieces and compose them into final code.

Of course, roles fits the pattern perfectly...

Perl Weekly Challenge # 50: Merge Intervals and Noble Numbers

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

Task 1: Merge Intervals

Write a script to merge the given intervals where ever possible.

[2,7], [3,9], [10,12], [15,19], [18,22]

The script should merge [2, 7] and [3, 9] together to return [2, 9].

Similarly it should also merge [15, 19] and [18, 22] together to return [15, 22].

The final result should be something like below:

[2, 9], [10, 12], [15, 22]

The example shows that intervals should be merged only if they overlap, but not if they are contiguous (in the example, [2,9] is not merged with [10, 12]).

Merge Intervals in Perl

For each interval except the first one, we check whether it overlaps with the previous one (stored in the $current variable); if it does overlap, we build a new interval merging it with $current.

A Static Archive of use.perl.org

In my previous post I added a footnote that "use.perl.org is difficult to get info out of now, it's basically dead. A lot of content is lost". That turned out to be not entirely true, it just needed some work to get to it

In the reddit comments, brian d foy mentioned Léon's WWW::UsePerl::Server, a module to host the use.perl.org archive.

I grabbed the archive, Léon's module, installed all the deps, got it up and running after hacking the module to work with the latest Catalyst, then combined some sed, awk, perl, SQL to create a static version of the site with URLs that allow it to function correctly: https://use-perl.github.io/. Note that the change in the URL structure to get it to work a) as a static site, and b) on github pages, means that any "permalinks" that might exist elsewhere in reference to it will need manual fiddling to get to the page in question - the URL structure should be relatively obvious however.

Risk increased by checking the number of subroutine arguments

The current subroutine signature specification checks the number of subroutine arguments.

On the other hand, there is actually risks of increasing by checking the argument count.

Risk increased by checking the number of subroutine arguments - Perl Subroutine Signatures Opinion Blog

Dancer2 0.208002

Your gift is arriving just a bit early this year: a new Dancer2 just in time for the holidays!

There are a number of documentation fixes and enhancements in this version. The largest change you will see under the hood removes Return::MultiLevel (and therefore Scope::Upper) from the list of Dancer2 dependencies, and makes your favorite lightweight web application framework just a little bit lighter.

The full changelog follows:

Perl Weekly Challenge: Smallest Multiple and LRU Cache

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

Spoiler Alert: This weekly challenge deadline is due in a couple of days (March 1, 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: Smallest Multiple

Write a script to accept a positive number as command line argument and print the smallest multiple of the given number consists of digits 0 and 1.

For example:

For given number 55, the smallest multiple is 110 consisting of digits 0 and 1.

Paws XXXVI (Still not finished.)

Well finally got the last of my tests done for S3, not much of a story as most of the test cases at least for the 'PUT' actions cases were mostly made up of two tests 'load' the results class and check the value of the '_request_id'.

That being said I still had some 80 tests that where failing most of them where this '_request_id' test. Seems when I was doing my test generator I was creating the test for '_request_id' but forgot to add it to the test content.

So a little change to 'FullTestMakerLWPCaller.pm'

Are array and hash representations really needed in subroutine signatures?

Are array and hash representations really needed?

Currently, "@foo" is proposed as the array representation. "%foo" is proposed as the representation of the hash.

Are array and hash representations really needed?

Perl Weekly Challenge 038: Date Finder and Word Game

Date Finder

Create a script to accept a 7 digits number, where the first number can only be 1 or 2. The second and third digits can be anything 0-9. The fourth and fifth digits corresponds to the month i.e. 01, 02, 03…, 11, 12. And the last 2 digits respresents the days in the month i.e. 01, 02, 03…, 29, 30, 31. Your script should validate if the given number is valid as per the rule and then convert into human readable format date.

RULES

  1. If 1st digit is 1, then prepend 20 otherwise 19 to the 2nd and 3rd digits to make it 4-digits year.
  2. The 4th and 5th digits together should be a valid month.
  3. The 6th and 7th digits together should be a valid day for the above month.

For example, the given number is 2230120, it should print 1923-01-20.

As we’ve done several times, we’ll use the core module Time::Piece to handle dates.

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.