Spoiler Alert: This weekly challenge deadline is due in a few days from now (on December 31, 2023 at 23:59). This blog post provides some solutions to this challenge. Please don’t read on if you intend to complete the challenge on your own.
Task 1: Equal Pairs
You are given an array of integers with even number of elements.
Write a script to divide the given array into equal pairs such that:
a) Each element belongs to exactly one pair.b) The elements present in a pair are equal.
First of all, a greeting. I posted an introduction with a notification of intent to take over a module on CPAN, but the maintainer responded to me. I'm Avery, I'm developing SeekMIDI, a small graphical MIDI sequencer. I started it in 2016 and I took a long break from programming entirely, and I've just restarted developing my programming skills again. For starters, I'm working on Perl Weekly Challenges and bug fixes to modules.
Without further ado, here are my solutions to the PWC #208. All solutions are about to be posted, but this could be a spoiler if you're trying to solve it too. I was very pleased this week that I got it down to about 15-25 minutes for each task, so I'm definitely getting more comfortable in Perl again.
By default, the test actions of both ExtUtils::MakeMaker and Module::Build test t/*.t in lexicographic order (a.k.a. ASCIIbetical order). Under this default, some Perl module authors who want tests performed in a given order have resorted to numbering tests: t/01_basic.t, t/10_functional.t, and so on.
My personal preference is to take the lexicographic ordering into consideration when naming test files: t/basic.t through t/whole_thing.t. But the price of this choice is a certain number of contrived test names, and even the occasional thesaurus lookup.
But there is a better way. Both ExtUtils::MakeMaker and Module::Build allow you to specify tests explicitly.
Under ExtUtils::MakeMaker version 6.76 or above, you call WriteMakeFile() thus:
Spoiler Alert: This weekly challenge deadline is due in a few days from now (on December 24, 2023, at 23:59). This blog post provides some solutions to this challenge. Please don’t read on if you intend to complete the challenge on your own.
Task 1: Submatrix Sum
You are given a NxM matrix A of integers.
Write a script to construct a (N-1)x(M-1) matrix B having elements that are the sum over the 2x2 submatrices of A,
I was doing some data pipelining and dockerising my creation.
And - as always - when testing and devving I forgot to set the right
environment variables. And when container image gets passed around,
the information about the required env settings will certainly get lost.
Here is something of a solution to that:
How to ensure you have the environment variables and values you need?
Here is a common sight:
$ PLAEC='Stockholm'
$ if [[ "$PLACE" == '' ]]; then echo "Normal OK"; fi
OK
... And the program fails with no errors!
Not quite what we want!
Another example, from a docker container image I created lately:
Paul and Philippe attended (Rik is still enjoying Australia).
We discussed:
feature-class: there’s a soon-to-be-merged PR to fix most memory leaks https://github.com/Perl/perl5/pull/20809
n-at-a-time map/grep: HAARG should reply to any remaining open questions, so that we can likely move the RFC to the next step of the process (“Exploratory”)
SSL in core: it’s still not in core, and there’s an open PR to just dual-life the SSL modules, but that’s unlikely to be the solution we’re looking for. Also, we’re still looking for a project manager for this project. Enquire Within.
RFC0013: awaiting the ability to store more information in the interpreter about overload (for API version and flags)
One of the modules bundled with Type::Tiny is Type::Params, a module that allows you to validate subroutine signatures using type constraints. It's one of the more popular parts of the suite.
This article provides a few hints for using it effectively.
Spoiler Alert: This weekly challenge deadline is due in a few days from now (on December 24, 2023 at 23:59). This blog post provides some solutions to this challenge. Please don’t read on if you intend to complete the challenge on your own.
Task 1: Shortest Distance
You are given a string and a character in the given string.
Write a script to return an array of integers of size same as length of the given string such that:
distance[i] is the distance from index i to the closest occurrence of the given character in the given string.
The distance between two indices i and j is abs(i - j).
I asked ChatGPT to suggest some new keywords that might make Perl more desirable. Here's the dialog:
JOHN: suggest some new keywords that Perl could add to its core syntax that would make the language more desirable to modern programmers
CHATGPT: Perl is a mature language that has undergone significant development since its inception. Despite this, there are always new features that can be added to a language to improve its appeal to modern programmers. Here are some suggestions for new keywords that Perl could add to its core syntax:
async and await: Asynchronous programming has become an increasingly important aspect of modern programming. Adding support for async and await keywords in Perl would enable developers to write non-blocking code that can take full advantage of modern hardware.
let: The let keyword is commonly used in languages like JavaScript and Rust to create variables with a limited scope. Adding let to Perl would make it easier to write clean and concise code.
Recently I received a bump on a GitHub pull request. This surprised me, because I was unaware of anything outstanding. I was even more surprised when I discovered that the distribution in question also had two open issues, one dating back about three months.
I have no idea why I was oblivious to these, but it made me want to audit myself to see if any other distributions had the same problem. GitHub has these nice links at the top of the page, Pull requests and Issues, but these show pull requests and issues that I initiated. I found no obvious way to display pull requests or issues filed against my repositories.
Guys anything can happen. There is literally no way of avoiding something that you haven’t prepared for. So in the face of mounting anxiety over the huge number of unexpected scenarios that may be around the corner, what can you do? You can contemplate insulating yourself, try and minimise the hazards, control your environment to a fine level of detail so that the surprises are infrequent and hazards are mitigated. At work I am drowned in Health and Safety Guidance, IT security protocols, Fire Safety Training. This means that work is to a large extent a somewhat boringly protected environment for me, my colleagues and my patients. Yet, even this can not avoid surprises. So what about your home, sitting in front of your computer. All the protection provided by protocols here are more vague, less policed, seen more as guidelines rather than mandatory.
Spoiler Alert: This weekly challenge deadline is due in a few days from now (on December 17, 2023, at 23:59). This blog post provides some solutions to this challenge. Please don’t read on if you intend to complete the challenge on your own.
Task 2: Most Frequent Letter Pair
You are given a string S of lower case letters 'a'..'z'.
Write a script that finds the pair of consecutive letters in S that appears most frequently. If there is more than one such pair, chose the one that is the lexicographically first.
PayProp is an automated payment and reconciliation platform specific to the lettings industry that is both easier to use and more powerful than solutions offered by banks and traditional software vendors.
The Perl Toolchain Summit is the annual event that brings together the key developers working on the Perl toolchain. The 13th summit (after a three year hiatus in 2020-2022) is in France this year, in late April.
It is, at its heart, an in-person event: about thirty people will spend four days in confined spaces, exchanging ideas and patches. And also droplets. To keep everyone safe, we have prepared a COVID policy.
inclusion of TLS libraries in the core: we think we should just try the “dual life” path, and see where that gets us.
n-at-a-time map/grep: Paul suspects it’s impossible to properly disambiguate my ($var, ...) from the EXPR case, and we wonder if the only choice is between having new keywords and dropping the EXPR case.
Spoiler Alert: This weekly challenge deadline is due in a few days from now (on December 10, 2023 at 23:59). This blog post provides some solutions to this challenge. Please don’t read on if you intend to complete the challenge on your own.
Task 1: Linear Recurrence of Second Order
You are given an array @a of five integers.
Write a script to decide whether the given integers form a linear recurrence of second order with integer factors.
For kicks I asked GPT to speculate about how we might improve Perl syntax with types and better object orientation. It generated the follow code and descriptions. Yes I know there's some errors in the code, I'm just presenting this as Chat GPT wrote it.
FWIW it looks a lot like what I see coming out of Corrina.
JOHN: If you wanted to improve Perl by adding types and object orientation what would you do. Give an example.
CHATGPT: Perl already has a limited form of object orientation, and there are also ways to add type checking through modules like Type::Tiny and Moose. However, if you were looking to significantly improve Perl's support for types and object orientation, there are a few different directions you could take.
Just like domain name registrations, SSL certificates need to be renewed regularly, otherwise they expire. This means you now have one more thing to monitor. Let's look at ways to do this in Perl, curl and Go. We'll also get a quick introduction to a hosted Mojolicious app that I wrote to make this even easier.