To-Study Plan: a beginning to OO in Perl

Now I have a todo list command-line script. I want to have a to-do list for my wikipedia editing activities, a to-study list for math I want to study sparely, a to-study-or-to-code in computer programming and maybe a to-read list for books.

The current format of the todo list script is roughly like this:

C:\Users\user>todo.pl h

Perl Weekly Challenge 051: 3 Sum and Colourful Numbers

3 Sum

Given an array @L of integers. Write a script to find all unique triplets such that a + b + c is same as the given target T. Also make sure a <= b <= c.

Here is wiki page for more information.

Example:

@L = (-25, -10, -7, -3, 2, 4, 8, 10);

One such triplet for target 0 i.e. -10 + 2 + 8 = 0.

I hadn’t checked the wiki page before writing my solution; and I hadn’t changed the solution after I read it. Therefore, it presents the naive and inefficient solution that iterates over all the possible triplets (but not starting from 0 in the inner loops to avoid checking the same triplet several times).

# Perl Weekly Challenge: sums

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

I’m involved in the organization of local elections here in France this weekend and don’t have time for completing this week’s Perl Weekly Challenge. I’ll cover only task 1 (sums), and only in Raku.

Task 1: sums in Raku

Given an array @L of integers. Write a script to find all unique triplets such that a + b + c is same as the given target T. Also make sure a <= b <= c.

Here is wiki page for more information.

Example:

@L = (-25, -10, -7, -3, 2, 4, 8, 10);

One such triplet for target 0 i.e. -10 + 2 + 8 = 0.

We can simply use the built-in combinations method to generate all possible triplets and check fort each whether the sum is 0:

BLOG: The Weekly Challenge #051

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

CY's Take on Perl Weekly Challenge #052

This is a part of Perl Weekly Challenge(PWC) #052 and the followings are related to my solution. 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) if possible, before reading my blog post.

Do tell me if I am wrong or you strongly oppose my statements!

I register a free account on blogs.perl.org . The process is surprisingly easy but I am a bit nervous that my posts are put along those of experienced coders on the frontpage of blogs.perl.org .

Back to the main topic.

Perl Weekly Challenge 050: Merge Intervals and Noble Integer

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]

This sounds so similar to PWC 039 I first thought I could solve it in the same way. Unfortunately, Set::IntSpan gives a different result:

PAWS Almost

I think in my last post I said this is going to be a very short series well I think I am wrong on that count.

When I last posted on the Kinesis 'SubscribeToShard' action I discovered that it is returning a 'application/vnd.amazon.eventstream' and that lead me down a very deep rabbit hole that got me well sidetracked.

Well to start out I had to figure out what AWS was returning when it was sending 'vnd.amason.eventstream' I eventually found that here Event Stream Encoding

Ok time to take the way-back machine to my first play-dates with computers, assembling GIS data from an Amdahl mainframe that was spooling a 9inch tape directly to my Unitron 2000

U2000_AII_TOP.jpg

over a 330 baud modem, Then taking the various bits, and putting them back together so I could draw pretty maps on this;

9928951466280032549.JPG

Though my one was the budget 880.

Monthly Report - February

Looking back at my last month performance, I get mixed feelings. I feel bad that I only submitted 7 Pull Requests. It is not that I didn't try to up the number. I noticed some of my past Pull Request disappearing from GitHub. It is affecting my Pull Request Stats. I keep all contributions record under my GitHub profile. It gives me sense of accomplishments.

The best part of last month was that I finally started taking part in The Weekly Challenge. Not only just code contributions but also blogged about it. It was possible because of help by fellow Team PWC member, Ryan Thompson.

What am I looking forward in the month of March? Well, I am looking forward to celebrate the completion of one year of "Perl Weekly Challenge" on 25th March 2020.

In my last report, I mentioned about my Dad's health. I am happy to announce that he is doing better and no longer dependent on others.

Let's take a quick look through last month main activities.

Write Codes, not Op - on Indention

As I heard from many posts on those online communities, Perl had been described as "hard to read"/"write once, modify never"/"oversophisticated"... These did not match my personal experience. Recently I have discovered that there is a Perl style guideline on the official site!

https://perldoc.perl.org/perlstyle.html

... Time to set your programming editor as having 4-space indent. (I use Vim.) :)

Narrowly destricted refs

*{; no strict 'refs'; \*{ "${pkg}::type" } } = sub () { $type };
push @{; no strict 'refs'; \@{ "${pkg}::ISA" } }, __PACKAGE__;
# ... and so on

I really don’t feel like I have anything to add but I suppose it may not be obvious that the point of this exercise is to surgically limit the lifting of the refs stricture to just the desired symbolic dereference (without leaking it even as far as any other part of the expression) – in the most compact form possible.

I also suppose I ought to expand on it by way of explanation for the less travelled in the dustier corners of Perl 5 syntax:

Perl Weekly Challenge 049: Smallest Multiple and LRU Cache

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.

The simplest naive solution is to start from the input number, keep adding it to itself until the result consists of 0's and 1's exclusively.

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.

On my technical Background - a beginner's story

Different people have come to an interest or develop a skill for different reasons. Nowadays, lots people are learning Python, R, JavaScript, Java, etc. for job hunting as data scientists or software engineers...

Beginner's Enthusiasm in Programming

For me, solitaires (games) always attract me. Programming has been felt like a solitaire . (Some people must disagree with me on this line. They are lucky. And I also want myself can grow as strong as a contributor to the opensource programming community.) Testing. Possible modifications. I learnt LOGO programming language in the primary school. As I can remember, while I was in junior high school, I lost my sleep one night just because of thinking using LOGO to write a Chinese Chess program! (The workload would be too much... LOGO is derived from LISP, I know. Ha.)

BLOG: The Weekly Challenge #050

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

Monitorix 3.12.0 released

Another great Perl software that I find very useful is Monitorix.

Monitorix is FOSS lightweight system monitoring designed to monitor as many services and system resources as possible.

system.png

The tl;dr is that it works really well for monitoring stand alone machines- which is what I used it for. It's tracks all sorts of metrics with minimal configuration by me, and with packages for most distros its trivial to install and update.

Version 3.21.0 was released this week with new features and fixes.

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.

Perl Weekly Challenge 048: Survivor and Palindrome Dates

Survivor

There are 50 people standing in a circle in position 1 to 50. The person standing at position 1 has a sword. He kills the next person i.e. standing at position 2 and pass on the sword to the immediate next i.e. person standing at position 3. Now the person at position 3 does the same and it goes on until only one survives.
Write a script to find out the survivor.

I tried two different approaches to the problem.

The first one uses an array of living people and a variable $sword that stores the index of the person holding the sword. In each iteration of the loop, the next person is removed from the array, and the sword is passed to the next person.

The “next person” has a special cyclic meaning: at the end of the array, the sword must return to the beginning. This is achieved by using the modulo operator %. Note that we use it twice, once to find the person to kill, and once to find the person to pass the sword to—and each case uses a different array size in the modulo operation, as killing a person changes the size of the array.

BLOG: The Weekly Challenge #049

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

Possibly the best k-means clustering ... in the world!

Short post this time because I got nerd-sniped looking at the data. The fun part is that you quickly move from thinking about how to get your results to trying to work out what they mean.

Forget why I started down this road. Right now, we are seeking the answer to Lewis Carol's famous question, How is a Porsche 914-2 like a Volvo 142E? (well, that's what it was in the first draft) A quick summary for those who have just joined us.

pdl> use PDL::IO::CSV ':all'
pdl> $cars = rcsv2D('mtcars_001.csv', [1 .. 11], {text2bad => 1, header => 1, debug => 1});
pdl> p $cars->dims
32 11

You got 32 11, right?

Perl Weekly Challenge 48: Survivor and Palindrome Dates

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

Spoiler Alert: This weekly challenge deadline is due in a couple of days (February 23, 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: The Survivor

There are 50 people standing in a circle in positions 1 to 50. The person standing at position 1 has a sword. He kills the next person i.e. standing at position 2 and passes on the sword to the immediate next, i.e. person standing at position 3. Now the person at position 3 does the same and it goes on until only one survives.

Write a script to find out the survivor.

This is sometimes called the Josephus Problem, named after Flavius Josephus, a Jewish historian of the 1st century who allegedly escaped collective suicide of defeated Jewish soldiers trapped by Roman soldiers by finding the right position to be the survivor.

About blogs.perl.org

blogs.perl.org is a common blogging platform for the Perl community. Written in Perl and offering the modern features you’ve come to expect in blog platforms, the site is hosted by Dave Cross and Aaron Crane, with a design donated by Six Apart, Ltd.