Perl Weekly Challenge 116: Number Sequence and Sum of Squares

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

Spoiler Alert: This weekly challenge deadline is due in a couple of days (June 13, 2021). 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 Sequence

  • You are given a number $N >= 10.*

  • Write a script to split the given number such that the difference between two consecutive numbers is always 1 and it shouldn’t have leading 0.*

Print the given number if it impossible to split the number.

Example:

BLOG: The Weekly Challenge #070

https://perlweeklychallenge.org/blog/weekly-challenge-070

CY's Take on PWC#067

This is a part of Perl Weekly Challenge(PWC) and the followings are related to my solutions. If you want to challenge yourself on Perl, go to https://perlweeklychallenge.org, code the latest challenges, submit codes on-time (by GitHub or email)(before Monday GMT+0 00:00) if possible, before reading my blog post.


The discussion of Perl 7 in blogs.perl.org # was so hot last week made me too shy to write PWC experience (stop, it's just an excuse!).

Some discussions were quite technical for a beginner. Anyway as a beginning coder in Perl 5, I would add "use warnings" in my final coding stage from now on to prepare for the change.

PWC#67 Task #2: Letter Phone

Lucky Number Per7

I swear it was Perl 5 just a moment ago. I turned my back for all of 5 minutes ...

I don't need the new features, but I don't like boilerplate and I'm happy to accommodate those who seek progress. Harking back to lessons from the past, SysAdmins of a certain age may remember the venerable a2p program for converting awk scripts to perl and the horrendous (but working) code that it produced. We had one of those running in production less than 2 years ago until I finally decided to re-write it in Modern Perl. A bit like moving house, as a community we need to face the pain every so often and address the risks and ptifalls, not as reasons to keep to the status quo, but as a checklist of problems to be solved.

Perhaps the most Perlish thing to do would be to actually go and ask the Python community what they would do differently in migrating to python3. Learn from other people's mistakes.

Perl Weekly Challenge 115: String Chain and Largest Multiple

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

Spoiler Alert: This weekly challenge deadline is due in a couple of days (June 6, 2021). 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: String Chain

You are given an array of strings.

Write a script to find out if the given strings can be chained to form a circle. Print 1 if found otherwise 0.

A string $S can be put before another string $T in circle if the last character of $S is same as first character of $T.

Examples:

Input: @S = ("abc", "dea", "cd")
Output: 1 as we can form circle e.g. "abc", "cd", "dea".

Input: @S = ("ade", "cbd", "fgh")
Output: 0 as we can't form circle.

Breathing life into the (Emacs) cperl-mode

If you are an Emacs user, you might know or even use cperl-mode. I am using it, more or less since my first days with Perl. Back then, newsgroups were a thing, and Ilya Zakharevich recommended it occasionally. In older times cperl-mode was shipped with Perl, today it is part of Emacs.
If you use cperl-mode, you might also have had a look at the code and noticed that it hasn't seen much love in the last decade or so.
Perl, on the other hand, evolves. Version 5.32, for example, brings a new infix operator, and some future version might bring Cor.
Wouldn't it be nice if cperl-mode understood these new keywords?
I'm on my way to get familiar with emacs-lisp, ERT, and other stuff to see what I can do.
Ideas, contributions, comments, bug requests and criticism is welcome - There's a GitHub repository to get started.

From the user perspective, Perl strings have no bugs and work well.

I feel that in the upcoming version of Perl, the core team fixes the Unicode bug as a reason to break backward compatibility Perl 5.

Unicode in Perl internally has some inconsistencies due to conflicts between latin-1 and UTF-8.

this is true.

On the other hand, from the user's point of view, a Perl string works perfectly fine if you only accept it can't tell whether it's a decoded string or a bytes.

We are solving this problem by convention.

Where do we determine if it is a string or a bytes?

The inside and outside of the program are completely separate.

If the data comes in from outside, then we will determine if it is a bytes or a string.

If it is a bytes, do nothing.

If it is a string, decode it.

This is simple and all of all works well.

In fact, this way is a good one.

Inside the program, we don't need to worry about the character code.

Monthly Report - June

COVID-19 seems to be still haunting us but life is getting back to normal slowly. I had the pleasure to attend the first "Conference in the Cloud". It was 3 days event. I booked 3 days off from the work so that I can focus on the event without any interruptions. It was my first experience attending event in the cloud. I found it hard to focus on the talk in general.

Could it be as I was at home with kids running around?

The day one itself started on a very happy note with the announcement of "Perl 7" by Sawyer X. The entire day one was dedicated to this very topic. brian d foy even had his first book "Preparing for Perl 7" launched with the announcement. Thanks to the author brian d foy, I had the pleasure to read the first copy of the book. I simply loved it. The best introductory book on Perl 7 so far. Please go and check out yourself.

Perl Weekly Challenge 114: Next Palindrome Number and Higher Integer Set Bits

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

Spoiler Alert: This weekly challenge deadline is due in a few days (May 30, 2021). 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: Next Palindrome Number

You are given a positive integer $N.

Write a script to find out the next Palindrome Number higher than the given integer $N.

Example:

Input: $N = 1234
Output: 1331

Input: $N = 999
Output: 1001

Next Palindrome Number in Raku

Perl 7: A Risk-Benefit Analysis

At the recent Conference in the Cloud for Perl and Raku, Sawyer X (the pumpking of Perl) announced an ambitious plan for Perl 7. Since Perl 6 was renamed to Raku to better communicate its fundamental differences from the well known identity of Perl, major versions are now available again for Perl to leverage, and it is a very important step to show that the language is still developed and used. I completely agree with the motivation and ideals presented, and have thought a lot about the benefits and risks involved in such ideas long before I was aware of this project.

Thinking and Question of The Proposal for Perl 7 - day1

I write my thinking and question about Proposal for Perl 7.

The Proposal for Perl 7

1. MAJOR version when you make incompatible API changes,

First of all, I am wondering about this assumption.

This is because there are very few incompatible API changes in Perl's history (Perl 1, 2, 3, 4, 5).

If the Python developers are thinking this way, it makes sense.

Has Perl ever thought of this in history?

Perhaps Perl has kept the maximum backward compatibility even in the major version upgrade?

The fact about Perl (rather than theory or ideal) is that Perl has kept its backward compatibility so that it can execute the assets of older programs.

Perl has taken care of old users who use Perl for a long time and cannot easily change their habits.

I believe this is Perl's kindness.

Perl is a language that emphasizes facts, reality and work, practicality.

Perl 5 has been very successful because it keeps backword compatibility with Perl 4.

I believe that this idea will be very successful even when upgrading from Perl 5 to Perl 7.

Because it really succeeded.

BLOG: The Weekly Challenge #066

https://perlweeklychallenge.org/blog/weekly-challenge-066

Perl Weekly Challenge 113: Represent Integer and Recreate Binary Tree

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

Task 1: Represent Integer

You are given a positive integer $N and a digit $D.

Write a script to check if $N can be represented as a sum of positive integers having $D at least once. If check passes print 1 otherwise 0.

Example:

Input: $N = 25, $D = 7
Output: 0 as there are 2 numbers between 1 and 25 having the digit 7 i.e. 7 and 17. If we add up both we don't get 25.

Input: $N = 24, $D = 7
Output: 1

I’m very late and have very little time this week, so I’ll implement this task only in Raku.

Represent Integer in Raku

Please not yet-another-oo-system, let's support frameworks

I'm very keen to be actively deprecating and removing syntactic oddities that folks should already be prohibiting via good perlcritic policies (i.e linting) hopefully in their editors and CI pipelines.

And standard perl is a good way for code bases to prepare for the future and derive real benefits right now. Both build on the meritocracy approach of CPAN.

It is that meritocracy that brought us the object frameworks Moose (which people seemed to feel was too big) and then Moo+Type::Tiny (which people seem to feel is about right). There are many other frameworks (object systems) which perl's minimalist internal object functions enable people to write, if one of them strikes a better balance of trade off's then there is nothing to stop it supplanting Moo as number one.

Perl 7 Thoughts

Overall, I think the Perl 7 announcement is great news.

I only have one small objection:

Perl 7, not quite getting better yet

Hegel remarks somewhere that all great world-historic facts and personages appear, so to speak, twice. He forgot to add: the first time as tragedy, the second time as farce.

The Eighteenth Brumaire of Louis Napoleon - Karl Marx

Sawyer just announced his plans for perl 7. And while Perl 7 sounds like a lovely language, I do see a number of issues:

Cohabitation / Forking

The proposal is presented as a linear progress, I don't believe this is realistic. This would be fork much like the python 3 transition is (which also wanted to be a simple linear progression). As we all know, they're currently in year 12 of a 5 year transition.

There are several problems here. CPAN as an ecosystem is the one that is given most attention to (not without reason; it is without doubt the most important collection of Perl code), but it's not even the biggest problem.

Perl Weekly Challenge 112: Canonical Path and Climb Stairs

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

Spoiler Alert: This weekly challenge deadline is due in a few days (May 16, 2021). 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: Canonical Path

You are given a string path, starting with a slash ‘/’.

Write a script to convert the given absolute path to the simplified canonical path.

In a Unix-style file system:

- A period ’.’ refers to the current directory

- A double period ’..’ refers to the directory up a level

- Multiple consecutive slashes (’//’) are treated as a single slash ’/’

The canonical path format:

- The path starts with a single slash ’/’.

- Any two directories are separated by a single slash ’/’.

- The path does not end with a trailing ’/’.

- The path only contains the directories on the path from the root directory to the target file or directory

Example:

BLOG: The Weekly Challenge #069

https://perlweeklychallenge.org/blog/weekly-challenge-069

CY's take on PWC#065

Good morning from the Asian timezone.

This is a part of Perl Weekly Challenge(PWC) and the followings are related to my solutions. If you want to challenge yourself on Perl, go to https://perlweeklychallenge.org, code the latest challenges, submit codes on-time (by GitHub or email)(before Monday GMT+0 00:00) if possible, before reading my blog post.

🤔

The Secret XS Diaries

I just rediscovered an old project of myself when I was learning Perl/XS and wanted to drop a hint to it here.

It might be useful for others who also have no idea how XS works and who would benefit from the approach and point of view of another XS newbie.

It is both the step-by-step description and a CPAN-ready Perl distribution.

You can find it on github:

Acme::The::Secret::XS::Diaries

Happy hacking.

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.