Perl Weekly Challenge 80: Smallest Positive Number Bits and Count Candies

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

Spoiler Alert: This weekly challenge deadline is due in several days (October 4, 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 Positive Number Bits

You are given unsorted list of integers @N.

Write a script to find out the smallest positive number missing.

Example 1:

Input: @N = (5, 2, -2, 0)
Output: 1

Example 2:

Input: @N = (1, 8, -1)
Output: 2

Example 3:

Input: @N = (2, 0, -1)
Output: 1

Smallest Positive Integer Missing in Raku

Extracting coronavirus SARS-CoV-2 spike protein sequences with BioPerl

As I started learning Perl I found out that there is a collection of Perl modules for bioinformatics tasks and it is called BioPerl. Intrigued I decided to try to use it for a simple task as it would help me in learning Perl. So the next question was: what task should I choose? Maybe download file with biological sequences, parse it and filter according some criteria? Thinking about this further I made a choice. I will work with sequences of infamous coronavirus which is more precisely named as SARS-CoV-2!

Spikes of coronaviruses – why are they so important?

BLOG: The Weekly Challenge #050

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

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:

Perl Weekly Challenge 79: Count Set Bits and Trapped Rain Water

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

Spoiler Alert: This weekly challenge deadline is due in a couple of days (September 27, 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: Count Set Bits

You are given a positive number $N.

Write a script to count the total number of set bits of the binary representations of all numbers from 1 to $N and return $total_count_set_bit % 1000000007.

Example 1:

  k-Means
k-Means-er

As we take another lap around the k-Means race trace, the Porsche 914-2 and Volvo 142E are still neck and neck. This time we'll try a straight-forward normalisation that linearly scales all values to the range [0,1] and see if they still end up in the same cluster.

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.

Perl Weekly Challenge 78: Leader Element and Left Rotation

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

Spoiler Alert: This weekly challenge deadline is due in a few days (September 20, 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: Leader Element

You are given an array @A containing distinct integers.

Write a script to find all leader elements in the array @A. Print (0) if none found.

An element is leader if it is greater than all the elements to its right side.

Example 1:

Input: @A = (9, 10, 7, 5, 6, 1)
Output: (10, 7, 6, 1)

Example 2:

Input: @A = (3, 4, 5)
Output: (5)

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

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: Fibonacci Sum and Lonely X

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

Spoiler Alert: This weekly challenge deadline is due in a couple of days (September 13, 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: Fibonacci Sum

You are given a positive integer $N.

Write a script to find out the smallest combination of Fibonacci Numbers required to get $N on addition.

You are NOT allowed to repeat a number. Print 0 if none found.

Example 1:

Input: $N = 6
Output:
    1 + 5 = 6

Example 2:

Input: $N = 9
Output:
    1 + 8 = 9

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.

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 76: Letter Grid

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

Spoiler Alert: This weekly challenge deadline is due in a few days from now (on Aug. 16, 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: Prime Sum

I’ve written a Raku program to solve this task, but it is unfortunately a bit buggy: it works in most cases, but there are a few rare cases where it doesn’t find the minimum number of prime numbers whose summation gives you the target number. I certainly don’t want to publish here a program which I know to be faulty in some cases, and I no longer have time before the deadline to fix it. So, I’ll skip this task for now.

Task #2: Word Search

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.

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

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.