PWC 055, Task #2: Wave Array

This blog post contains the "missing comments" from my contribution to the Perl Weekly Challenge 055. If you haven't read the Task #2 Problem Description: Wave Array you might want to do that first.

My submission for PWC 056 Task #2.

The Idea

Sort your array of numbers. Select a number. You have now two sub-arrays:
  1. The sub-array "to the left" of the selected number, and
  2. The sub-array "to the right" of the selected number.
This sounds trivial, but I want to point out that the setup has been done so that "less than or equal to" or "greater than or equal to" are not mentioned. These qualities are implicit with the sort of the data when we start. The algorithm then follows this idea:
  1. I have a sorted list of numbers listed vertically on a sheet of paper.
  2. I ask you to select any number in that list.
  3. I take that number, write it down,
  4. I draw a line through that number on the list.
REPEAT

BLOG: The Weekly Challenge #056

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

Revisiting the Collatz Sequence (PWC 54)

In my blog post related to Perl Weekly Challenge 54 posted on April 4, 2020, the section about the "extra credit" task concerning the Collatz conjecture described in some details the difficulties encountered when trying to cache the data: the volume of data is very large. I'm blogging again on the subject because of new findings.

The Collatz conjecture concerns a sequence defined as follows: start with any positive integer n. Then each term is obtained from the previous term as follows: if the previous term is even, the next term is one half of the previous term. If the previous term is odd, the next term is 3 times the previous term plus 1. For example, the Collatz sequence for 23 is this:

23 70 35 106 53 160 80 40 20 10 5 16 8 4 2 1

CY's take Perl Weekly Challenge on #055

This is a part of Perl Weekly Challenge(PWC) #055 and the followings are related to my solution.

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

named.jpg

Oh.

PWC 055, Task #1: Flip Binary

This blog post contains the "missing comments" from my contribution to the Perl Weekly Challenge 055. If you haven't read the Task #1 Problem Description: Flip Binary you might want to do that first.

Now to document a bit more, my submission for PWC 056 Task #1.

First, please feel free to suggest a better style of exposition. At work, I usually lard my code with comments galore, but with small demonstration programs I prefer to get as much code onto one page as possible, so now I'll try to illuminate a bit more my thoughts, no promises that they will be illuminating. Of course, let me know of any outright errors you catch as well, please.

The Idea

BLOG: The Weekly Challenge #055

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

Perl Weekly Challenge 55: Binary Numbers and Wave Arrays

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

Task # 1: Flipping Binary Numbers

You are given a binary number B, consisting of N binary digits 0 or 1: s0, s1, …, s(N-1).

Choose two indices L and R such that 0 ≤ L ≤ R < N and flip the digits s(L), s(L+1), …, s(R). By flipping, we mean change 0 to 1 and vice-versa.

For example, given the binary number 010, the possible flip pair results are listed below:

L=0, R=0 the result binary: 110
L=0, R=1 the result binary: 100
L=0, R=2 the result binary: 101
L=1, R=1 the result binary: 000
L=1, R=2 the result binary: 001
L=2, R=2 the result binary: 011

KBOS attributes

Welcome to the fifth post about the Kephra Base Object System, where I explain the need for three kinds of attributes: data, delegating and wrapping and gas a little about their properties. It is especially advised to have read the first part (scopes) and the previous part, since accessors are methods.

In case you wonder how practical this exercise is - I already implemented a slightly simpler version and currently rewrite it. It's a standalone bundle of modules with its own tests and docs named Base-Class (Kephra::Base::Class) (123kB), which depends only on the bundle Base (there are the data types) (32 kB). So once ready it could be released on CPAN without much work.

An existential threat (that isn't COVID-19)

Many of you will know my good friend Peter Scott as a Perl luminary. More recently he has turned his attention and his considerable talents to focus on the future of AI, both as an unprecedented opportunity for our society...and as an unprecedented threat to our species.

A few years back, he released an excellent book on the subject, and just recently he was invited to speak on the subject at TEDx. His talk brilliantly sums up both the extraordinary possibilities and the terrible risks inherent in turning over our decision-making to systems whose capacities are increasingly growing beyond our own abilities, and perhaps soon beyond even our own understanding.

Whether our accelerating use of AI brings us utopia or extinction, the very real possibility of either outcome surely makes these twelve minutes well worth paying attention to.

Dancer2 0.300001 Released

On behalf of the Dancer Core Team, I’d like to announce the availability of Dancer2 0.300001. This maintenance release brings brings a revamped tutorial, fixing of a YAML-related regression, repair of an encoding bug, and a slew of documentation fixes.

The full changelog is as follows:

Perl Weekly Challenge 054: Kth Permutation Sequence + Collatz Conjecture

Kth Permutation Sequence

Write a script to accept two integers n (>=1) and k (>=1). It should print the k-th permutation of n integers.

For example, n=3 and k=4, the possible permutation sequences are listed below:

123
132
213
231
312
321

The script should print the 4th permutation sequence 231.

The straightforward way is to generate all the permutations in the correct order and then output the kth one. To generate them, we can use recursion: To get all the permutations of n elements, start with each element and extend it with all the permutations of the remaining elements.

CY's take on PWC#054

This is a part of Perl Weekly Challenge(PWC) #054 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.


Apr03_2020.png

My laptop spent about 40.5 hours for calculating the list for the extra credit in task #2. While it was calculating, I found that my code hadn't been optimized. Anyway, even if I optimized it by 50%, the wait of 20 hours could still be a record for an impatient and blunt person like me.

2nd Apr, 2020
time | number_reached
1427 1
1745 309560
1809 325441
1831 339572
1852 353486
1951 386882
2205 453250
2253 475841
2308 482951
2358 502248

3rd Apr, 2020
time | number_reached
0419 600125
1405 772771
1534 794982
1538 796651
1543 798343
1555 800112 At this point, I realized that I should do more optimization.
1558 801872
1607 803625
1630 808808
1724 822777
1730 824482
1955 859075

Perl Weekly Challenge 54: k-th Permutation Sequence and the Collatz Conjecture

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

Spoiler Alert: This weekly challenge deadline is due in a couple of days (April 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: kth Permutation Sequence

Write a script to accept two integers n (>=1) and k (>=1). It should print the kth permutation of n integers. For more information, please follow the wiki page.

For example, n=3 and k=4, the possible permutation sequences are listed below:

BLOG: The Weekly Challenge #054

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

Keyhole surgery 100% successful

Part 1.

On Match 20th I had keyhole surgery to repair the aortic arch.

The lining had peeled off the wall. This happens when the lining develops a tear due to (in my case) childhood and later stress. Then, blood is pumped thru the tear and thus between the lining and the wall. Where the blood ought to go is called the 'true lumen' and when it's behind the lining and thus where is should not be - which is the bad news - , is called the 'false lumen'. So it's blood pressure in the false lumen which splits the lining off the wall. I just checked that original post and now realise I did not explain that at all.

Perl Weekly Challenge 053: Rotate Matrix and Vowel Strings

Rotate Matrix

Write a script to rotate the following matrix by given 90/180/270 degrees clockwise.
[ 1, 2, 3 ]
[ 4, 5, 6 ]
[ 7, 8, 9 ]

For example, if you rotate by 90 degrees then expected result should be like below

[ 7, 4, 1 ]
[ 8, 5, 2 ]
[ 9, 6, 3 ]

The easiest way to work with multidimensional data in Perl is PDL. Interestingly, I haven’t found a direct method to rotate a matrix in this way.

What I have found, though, was a method to transpose a matrix, which means to switch the columns and rows. The result for the sample input is

Rotation in R^2 - CY's take on PWC#053 Task 1

This is a part of Perl Weekly Challenge(PWC) #053 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!

Oh. Task #1 has been funner than what I thought. I would like to introduce the "advanced" version I coded; it requests a specific module to run; well, I write these codes while I am studying OO hence a package (or module?or class? Which word is more suitable?) exists).

I have supplied a simpler script on GitHub, where the idea is based on a spiral.
#the spiral for the simpler script
    3,  2,  1, 
    4,  X,  0, 
    5,  6,  7
- - - - - - - - - - - - - - -
The idea behind this so-called "advanced" version is based on linear transformations on plane. In words:

new_position_vector = ReverseTranslation(Rotation(Translation(old_position_vector))) .

Content inside xy.pm

Monthly Report - March

I lost a friend of mine, Jeff Goff (aka DrForr), who passed away on 13th March, 2020, while snorkeling with a group in the Bahamas. He will be missed by many of his friends. May his soul rest in peace.

Most of the time last month was occupied by COVID-19. Being a type-2 diabetic didn't help the cause either. I have suffered with consistent cough all my life. It is really scary when think from COVID-19 point of view. I have survived so far by the grace of ALLAH s.w.t.

I have been working from home since the first week of March. I have been kind of self quarantined. Kids, specially the twins (3 years old) not allowed to play with me. It is really hard to focus on work but somehow I have managed so far. I am getting used to it now.

Perl Weekly Challenge 53: Rotate Matrix and Vowel Strings

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

Spoiler Alert: This weekly challenge deadline is due in a couple of days (March 29, 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: Rotate Matrix

Write a script to rotate the following matrix by given 90/180/270 degrees clockwise.

[ 1, 2, 3 ]
[ 4, 5, 6 ]
[ 7, 8, 9 ]

For example, if you rotate by 90 degrees then expected result should be like below:

[ 7, 4, 1 ]
[ 8, 5, 2 ]
[ 9, 6, 3 ]

Back to Paws

It has been a little while since I played with my little PAWS and yes like many of us these days I have been just a little distracted, trip planned, trip changed, trip canceled etc etc etc.

Anyway to recap where I left off I was just getting the 'SubscribeToShard' action to work with a HTTP stream to work, after a fashion anyway. Then I got side tracked a little playing about with the problem of testing if the stream was correctly sending data down the pipe and if I was decoding it correctly.

As a byproduct of getting to the bottom of that I finally figured out what the PAWS 'Paginators' are for and I guess how to use them.

I noticed the odd "NextToken" tag in some of the Boto Json files as well most of the services have a ''paginators-1.json' definition file as well and looking at the Kinesis pod I see that there paginators listed.

PAGINATORS
Paginator methods are helpers that repetitively call methods that return partial results

About blogs.perl.org

blogs.perl.org is a common blogging platform for the Perl community. Written in Perl with a design donated by Six Apart, Ltd.