Spoiler Alert: This weekly challenge deadline is due in a few hours. 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: Isomorphic Strings
You are given two strings $A and $B.
Write a script to check if the given strings are Isomorphic. Print 1 if they are, otherwise 0.
A very welcome PR for adding the new SLA parameters for RT 4.4.3 was provided to RT::Client::REST on githib, which went out in v0.57 just earlier this week.
However this spurred me to take care of another PR that was been floating which allowed more verbose error messaging to be enabled. I also returned to my proposed fix for RT118729 which is because of mishandling of RT's strange "REST" (it's not really) interface.
If you are using RT::Client::REST i urge you to update it. Testing it carefully first before deploying. Bug reports are welcome especially when a fix is provided!
This is a part of Perl Weekly Challenge(PWC) #057 and the followings are related to my solution.
Do tell me if I am wrong or you strongly oppose my statements!
Task 1: Invert Tree
There is a module Tree::Binary on CPAN and its method "mirror" does what exactly describe in the Task 1. Of course, the experience of using a shortcut won't be filled a blog post.
Last week (PWC #056) I did not attempt the binary tree task but I did read the blogs of other PWC members.
Hence, it's time for my "blog report". Blog posts I use as reference are
Spoiler Alert: This weekly challenge deadline is due in a few days (December 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: Count Numbers
You are given a positive number $N.
Write a script to count number and display as you read it.
Example 1:
Input: $N = 1122234
Output: 21321314
as we read "two 1 three 2 one 3 one 4"
Let me start with the second task as it was definitely simpler (at least for me).
We iterate over all the input words. For each word, we try to find the shortest prefix possible. To know what prefixes have already been used, we keep two hashes: one stores the abandoned prefixes (i.e. those that were not unique anymore), the second one stores the “current” prefixes (the prefix is the key, the actual word is the value). We start from length 1 and add 1 in each step. If the prefix isn’t used and hasn’t been used, we assign it to the word and proceed to the next word. If the prefix is currently used for a different word, we store the prefix as “used” and prolong the prefix for the old word by one—but we continue the loop for the current word, in case their common prefix is longer.
The problem is in two parts, flipping the tree and pretty-printing it.
The flipping part is pretty easy, but since I'm a huge fan of Higher Order Perl I thought I should at least try to make it sort of like the tree walking code I remembered reading, where you give the tree-walker the function you want to operate on each node. (That word, "remembered" should be a hint that I haven't read the book in years and you should really go read the master.) I wrote both a depth-first and a breadth-first binary tree walker. For the purposes of flipping the whole tree, either one would have sufficed, but it is handy to have the option when you are experimenting.
Spoiler Alert: This weekly challenge deadline is due in a few days (December 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: DNA Sequence
DNA is a long, chainlike molecule which has two strands twisted into a double helix. The two strands are made up of simpler molecules called nucleotides. Each nucleotide is composed of one of the four nitrogen-containing nucleobases cytosine (C), guanine (G), adenine (A) and thymine (T).
You are given DNA sequence, GTAAACCCCTTTTCATTTAGACAGATCGACTCCTTATCCATTCTCAGAGATGTGTTGCTGGTCGCCG.
Write a script to print nucleobase count in the given DNA sequence. Also print the complementary sequence where Thymine (T) on one strand is always facing an adenine (A) and vice versa; guanine (G) is always facing a cytosine (C) and vice versa.
To get the complementary sequence use the following mapping:
Finally I saw posts of PWC#056 on blogs.perl.org .
I haven't found what to discuss about #056 Task #1. Just to keep people know this code producer is alive and healthy, I share my recent life:
On Perl resources:
1. Perl Monks
From a blogpost[1], I was hooked to https://www.perlmonks.com/ . Apart from many advanced Perl discussions, there is a book review section (not very active):
Yesterday I got the "Perl Debugged" and "Perl Best Practices" on my hand, which are both recommended for fresh-to-intermediate Perl programmers. Yeah!
( The Best Practices seems to be accepted as one of commons among Perl programmers. There is Perl::Critic (learnt from the PWC Champion Interview March 2020). And there is a reference sheet on the book. )
After posting two separate blogs for PWC 055 and seeing how awkward the explanations were, I'll try a new tack: Both submissions will be elaborated in one blog post. The elaborations will not be explanations. I'll focus more on the "idea" part and let any programming details come out in the comments, if at all.
For input I decided that all the numbers in the array would be command line arguments. That meant that 'k' would have to be a command line option. There was some validation that the stated requirements were met.
One input requirement "given an array @N of positive integers (sorted)" seemed to say that the input array should be sorted. The algorithm I chose worked without any sorting requirement on input, so this was not checked.
I’m collecting different setups here. Other efforts are underway to organize
a virtual conference. The setups listed below aim for smaller audiences with
hopefully lower effort in setting things up.
I don’t discuss the other stuff needed for organizing a conference, like
the social aspects (”hallway track”, “moderation”, “timekeeping”) or how
people can forward questions from the chat to the speaker. The logistic
aspects are mostly that outside of the “producer”, ideally nobody needs to
install software beyond Chromium or another browser compatible enough with
Jitsi to do video streaming.
Spoiler Alert: This weekly challenge deadline is due in a couple of days (November 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: Array of Products
You are given an array of positive integers @N.
Write a script to return an array @M where $M[i] is the product of all elements of @N except the index $N[i].
You are given an array @N of positive integers (sorted) and another non negative integer $k. Write a script to find if there exists 2 indices $i and $j such that $A[$i] - $A[$j] == $k and $i != $j. It should print the pairs of indices, if any such pairs exist.
Example:
@N = (2, 7, 9);
$k = 2;
Output: 2, 1
I totally ignored the fact that the input array is sorted. My solution works for any input array, but it’s still rather efficient.
The basic trick is that we don’t have to compute $A[$i] - $A[$j] for each combination or $i and $j. We know $k from the very beginning, so we can just iterate the array for the first time to store it in a hash, and iterate it for the second time to check the hash whether the corresponding number exists in the 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.
Sort your array of numbers. Select a number. You have now two sub-arrays:
The sub-array "to the left" of the selected number, and
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:
I have a sorted list of numbers listed vertically on a sheet of paper.
If you are using Docker, you may have noticed that it
creates random names for containers when you haven't provided any
specific name. These names are a combination of an adjective
and a proper name of an individual. The individuals are
famous men and women picked from the history of scientific exploration
and engineering.
This package allows you to use the same system in your own programs.
You would get combinations like
interesting_mendeleev,
epic_engelbart,
lucid_dhawan,
recursing_cori,
ecstatic_liskov and
busy_ardinghelli.
The combination boring_wozniak is not allowed because
Steve Wozniak is not boring.
This same limitation exists in the
original code.