Spoiler Alert: This weekly challenge deadline is due in a few days from now (on January 2, 2022 at 24:00). 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: Dot Product
This first task of this week’s challenge was covered in this blog post.
Task 2: Palindromic Tree
You are given a string $s.
Write a script to create a Palindromic Tree for the given string.
There are 28 entries on this blog in the Year 2020.
In February, I started to join "The Weekly Challenge"(PWC in short, as initially it was called "Perl Weekly Challenge" while the name "Perl6" hadn't been replaced by Raku). Then I slowly involved in the Perl community as a beginner.
At first, my codes were messy! I have forgotten from where I heard of Perl Best Practices(by Damian Conway; btw, I have to revisit it again), but have been trying to adopt some of its pieces of advice as many as possible. And then I read more codes and decided to maintain my code more modularized and structured; in addition, I have learnt to use the unit testing package in Perl (thanks to Perl Monks).
No, not at all. I like to find happiness in every little things in life. It is an art that I am still learning. I am writing this as a part of my monthly routine sharing last month activities. However this is special as it also has overall annual report of the year 2020.
I am embarassed looking back what I had planned at the start of the year.
Do I have any plan for 2021?
No way, I am not going to repeat my mistake. For a change, I want to see how I deal with my life without any plan.
Last January there was a post on reddit which claimed that my module JSON::Parse was not only failing some of the JSON Test Suite tests, but also crashing on one of them. Anyway I should have got around to doing something about it sooner, but here are my conclusions.
First of all there was a crash on one of the files, which went something like this: [{"":[{"":[{"", repeated about 100,000 times. (The actual file is here if you really want to see it.) Investigating it using a LInode, I found that after 80,000 open brackets the stack was overflowing, causing the crash to occur. If I added a printf in the midst of my code the printf would cause the stack overflow, so it wasn't actually due to my code but just because the stack size seems to be quite small on Linux.
Spoiler Alert: This weekly challenge deadline is due in a few days from now (on January 2, 2022 at 24:00). This blog post offers some solutions to this challenge, please don’t read on if you intend to complete the challenge on your own.
An important point is that we are told that the arrays have the same size. Thus, we don’t need to check that. We’ll also assume that they contain only numbers.
Using a similar approach than James Curtis-Smith , the solution looks at points with equal slope to see if they are in a straight line. Being less literate in Raku, using classes help me to organize coding ideas.
This exercise gives me the opportunity to work with the type BagHash. The highest value of the slopes stored in a BagHash gives the number of points in a straight line. Happily, the first example in Raku documentation is for a Class Point, an example reused in this solution.
These are some answers to the Week 93 of the Perl Weekly Challenge organized by Mohammad S. Anwar.
Spoiler Alert: This weekly challenge deadline is due in a few days (January 3, 2021). This blog post offers some solutions to this challenge, please don’t read on if you intend to complete the challenge on your own.
I'm not a great blogger - but I will try and explain my solutions to the Perl weekly challenge each week. I always try and look for interesting solutions to the problems at hand.
Part 1
Not sure on the correct way to do this... I first looked at all the pairs of points - and looked to see what the direction was between the points. For those where the y-coordinates are different you can just use (x1-x2)/(y1-y2) to represent the slope. We also that flipping the order of the points gives the same value. For those canses where y is the same - the slop can be represented by an "infinity value" in my case i use "-"
I managed to cause another set of obscure bugs by misusing newSVpv. The goal of this code is to split the RGB and the alpha (transparent) part of a PNG image, for the use of the PDF::Builder module on CPAN.
Here the SV in newSVpv is "scalar value", and the "pv" means "string". My code says this:
sv = newSVpv ("", len);
and it causes the crash on Solaris and other operating systems because the above statement is a bad idea. What happens is that Perl copies "len" bytes from my string, where "len" might be a very large number, for a large PNG image, but I've given it the string "" to copy from. So Perl tries to copy from uninitialised, or possibly even inaccessible, parts of the computer's memory. I found out my error only after almost giving up, by using valgrind to look for memory errors.
Spoiler Alert: This weekly challenge deadline is due in a few days from now (on December 26, 2021 at 24:00). 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: Semiprimes
Write a script to generate all Semiprime number <= 100.
For more information about Semiprime, please checkout the Wikipedia page.
In mathematics, a semiprime is a natural number that is the product of exactly two prime numbers. The two primes in the product may equal each other, so the semiprimes include the squares of prime numbers.
Example:
10 is Semiprime as 10 = 2 x 5
15 is Semiprime as 15 = 3 x 5
The most important Perl Governance poll yet has concluded. The position of Pumpking is no more, and is instead now held by a shared 3 person Steering Council, as defined in perlgov.pod: https://github.com/Perl/perl5/pull/18357/files
To quote RJBS:
Perl has two well-defined bodies involved in its governance: a core team of a few dozen and a steering council of three people. The core team sets the rules of Perl governance, votes on membership of the two groups, and delegates substantial decision making power to the steering council. The steering council has broad authority to make decisions about the development of the Perl language, the interpreter, and all other components, systems and processes that result in new releases of the language interpreter.
Right now, the core team has 25 members, although this may change over time.
The new Perl Steering Council is now:
RJBS + Neil Bowers + Sawyer X
Thanks to all of them for stepping up and donating their efforts to the Perl community. :)
These are some answers to the Week 92 of the Perl Weekly Challenge organized by Mohammad S. Anwar.
Spoiler Alert: This weekly challenge deadline is due in a few days (December 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.
I'm not a great blogger - but I will try and explain my solutions to the Perl weekly challenge each week. I always try and look for interesting solutions to the problems at hand.
Part 1
I started with what I thought was the best approach - keeping a hash of the letters in both words and if they don't match the required pattern then to return 0 otherwise return 1. But this looked rather messy. There must be a simpler, more elegant solution.
I thought how would I compare the words, and "normalisation" sprang to mind:
The Persuaders! is a particularly silly 1970s action TV series which lasted for only one season. Tony Curtis plays Danny Wilde to Roger Moore's Lord Brett Sinclair. Tony is the funny guy and Roger is the straight man. After the Persuaders, Roger Moore went on to become James Bond, and Tony Curtis went on to date Debee Ashby.
Although it wasn't a hit in America, The Persuaders actually became more popular in translation than in the original. One of the running gags is American Danny (Tony Curtis) making fun of snooty, toffee-nosed, upper-crust "your lordship" Roger Moore. But since the translated versions were for people who didn't know anything about British or American people, the translators invented new dialogue unrelated to the original, which ended up being more entertaining for the audience than the English dialogue. Which has nothing to do with Perl but here we go.
Spoiler Alert: This weekly challenge deadline is due in a few days from now (on December 19, 2021 at 24:00). 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: Calculator
You are given a string, $s, containing mathematical expression.
Write a script to print the result of the mathematical expression. To keep it simple, please only accept+ - * ().
It is a bit of a long story how I got burned by bad perl internal politics.
For many years I wanted images in Pod. And many others wanted too. And of course, each time I raised this in lists and on facebook, an answer was, if you want it, go and write it yourself. I would tell that myself, the classic "patches are welcome". Until one day I said, well, now, why actually not, right? Especially that I do have experience in creating and actively using images in pod using various hacks, such as direct inclusion of html with images, and even writing a standalone POD viewer capable of showing said images.
Need some joy this holiday season? Head over to the Dancer Advent Calendar for this year's Twelve Days of Dancer. With a little help from our friends, we've put together a 12-day mini advent calendar featuring some great software built in Dancer, some helpful tips and tricks, new features, and more.
Thanks for being such a great community, and for your continued support of Dancer! Wishing you the happiest of holiday seasons!
CromeDome (on behalf of the Dancer Core Developers)
Most operating systems have a version of libpng, the library for reading and writing the PNG (portable network graphics) image format on them. Unfortunately, though, the libpng is often fairly old.
I wrote a CPAN module which links against libpng, but then trying to get the module tested with CPAN testers, a lot of bugs would happen. It was frustrating because I couldn't work out what was going wrong with the tests unless I could find out what version of libpng was installed on the testing machine.
The solution I came up with in the end was a bogus test file which merely prints the libpng version as its skip_all message. This turned out to be quite effective in working out what is going wrong as various improvements to my PNG module turn out to trip bugs in older versions of libpng.
Spoiler Alert: This weekly challenge deadline is due in a few days from now (on December 12, 2021 at 24:00). 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: Divisor Last Digit
You are given positive integers, $m and $n.
Write a script to find total count of divisors of $m having last digit $n.
Example 1:
Input: $m = 24, $n = 2
Output: 2
The divisors of 24 are 1, 2, 3, 4, 6, 8 and 12.
There are only 2 divisors having last digit 2 are 2 and 12.
Update: Ben Bullock has provided script for my question. See the comment section. Thanks Ben.
---------------------
Happy New Year!
Today's data is about
$ perl pwc092-1_isomorphic.pl '茫茫人海' '夜夜笙歌' 0
--
Seeing others' post, I have a short reflection on dated The Weekly Challenge #092 Task 1 (statements / recap ), but may lead to a hike towards a hill in Perl.
Task statement:
TASK #1 › Isomorphic Strings
Submitted by: Mohammad S Anwar
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.
Example 1:
Input: $A = "abc"; $B = "xyz"
Output: 1
Example 2:
Input: $A = "abb"; $B = "xyy"
Output: 1
Example 3:
Input: $A = "sum"; $B = "add"
Output: 0
My unsatisfactory code (distaste due to the two subroutines &verify_pattern and &learn_pattern are almost the same).
Suddenly today I want to try out whether the Unicode support is direct; sadly, no:
Throwing this one out to the wider community, if anyone can assist in adding https support to strawberryperl.com that'd be great, with browsers and corporate firewalls moving towards a stricter mode of operation. An existing issue is here, with some history for those interested. Thanks in advance.
Perl returns its hash values in a random order. Since 5.14 or so, the
random order changes every time. So if you loop over your hash values,
you get a different ordering each time.
for my $k (keys %hash) { }
No problem you say, I'll use sort to order my keys.
for my $k (sort keys %hash) { }
But what if you want to use a non-default order, like
case-insensitive? Easy-peasy you claim.
for my $k (sort {uc ($a) cmp uc ($b)} keys %hash) { }
Now here's my problem. I'm using XS to loop through the hash, and I want to sort the keys in the hash according to the user's preference.