Perl Weekly Challenge 71: Peak Elements and Trim Linked List

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

Task 1: Peak Elements

You are given positive integer $N (>1).

Write a script to create an array of size $N with random unique elements between 1 and 50.

In the end it should print peak elements in the array, if found.

An array element is called peak if it is bigger than it’s neighbour.

Example 1:

Array: [ 18, 45, 38, 25, 10, 7, 21, 6, 28, 48 ]
Peak: [ 48, 45, 21 ]

Example 2:

Array: [ 47, 11, 32, 8, 1, 9, 39, 14, 36, 23 ]
Peak: [ 47, 32, 39, 36 ]

The specification somewhat lacks precision, but the examples are clear enough to clarify.

Peak Elements in Raku

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.

KBOS signatures

There are signatures in Raku, core Perl 5, Moose, Dios and lot of other modules. With KBOS I tried to find out how optimal signatures would look like to me. My objectives are: 3. easy to parse with the eye, 2. concise syntax and 1. delegates as much work as possible into the background so I have to write the least amount of code.

perlmodules.net remake

Hi. The current version of perlmodules.net was made in 2013/2014 with AngularJS, it is hard to update and so I’m starting a remake of the site.

Apart from an aesthetic makeover, it will be built with Vue.js/nuxt.js in order to allow the site to be indexed by all search engines. New features and ways of viewing the data may be added.

It will still use Mojolicious, but will use PostgreSQL instead of (the current site’s) MySQL, DBIx::Class instead of Rose::DB::Object, plus also Minion, RxJS, and will be open-sourced.

Help from the community will be very welcome. If anyone wants to join the discussion, please join our IRC channel, at irc://irc.freenode.net/#perlmodules.net

Perl Weekly Challenge 70: Character Swapping and Gray Code Sequence

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

Task 1: Character Swapping

You are given a string $S of size $N.

You are also given swap count $C and offset $O such that $C >= 1, $O >= 1, $C <= $O and $C + $O <= $N.

Write a script to perform character swapping like below:

$S[ 1 % $N ] <=> $S[ (1 + $O) % $N ]
$S[ 2 % $N ] <=> $S[ (2 + $O) % $N ]
$S[ 3 % $N ] <=> $S[ (3 + $O) % $N ]
...
...
$S[ $C % $N ] <=> $S[ ($C + $O) % $N ]

Example 1:

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.

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 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

BLOG: The Weekly Challenge #049

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

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 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.

# 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:

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?

My first date with Raku

https://perlweeklychallenge.org/blog/my-first-date-with-raku

KBOS types

After introducing KBOS I should write about the most fundamental concept in this Perl syntax extension. In fact it's so basic, you could use it even without objects.

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

Deprecating or Transferring Mojo::ACME

While Mojo::ACME was a fun experiment, it has several shortcomings at this point and I’ve officially stopped using it. If someone is interested in maintaining it, and if I’m sufficiently convinced of your credibility since this is a security module after all, I can hand it over. Otherwise I will be marking it as deprecated soon.

Announcing Zydeco

Technically, I already announced it, but now I've renamed it. MooX::Pression is now called Zydeco.

Moops had a memorable name, and I think the naming really helped it gain a following. MooX::Pression was just meh. So now it's Zydeco. Zydeco is a fun word and pretty short to type. It's a musical genre that blends jazz, blues, and Louisiana French Creole, and it just seemed like a good fit for a module that takes what I feel are some of the coolest features of Perl programming, and blends them together under one syntax.

Also, practising what I preach, Zydeco now has its own website.

http://zydeco.toby.ink/

av_fetch can return NULL

If you create an array by inserting values, in the following way,

$thing{key}[10] = 1;

and then don't populate the rest of the array, a call to av_fetch in the array to retrieve values lower than the tenth one may return a NULL value.

I found this out the hard way, by segmentation faults returned from the following dereference:

https://metacpan.org/source/BKB/JSON-Create-0.24/json-create-perl.c#L1021

The important thing to do here is not to rely on av_fetch to not return nulls. I fixed the problem in JSON::Create version 0.25:

https://metacpan.org/source/BKB/JSON-Create-0.25/json-create-perl.c#L1036

I chose to populate the output JSON with the JSON value "null" if there a NULL value is returned by av_fetch:

https://metacpan.org/source/BKB/JSON-Create-0.25/json-create-perl.c#L1044

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.