Perl Weekly Challenge 165: Scalable Vector Graphics

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

This week, Task 1 and part of Task 2 relate to Scalable Vector Graphics (SVG). I’d been using SVG a very long time ago and certainly didn’t remember any of the details. So, in my first blog relating to PWC 165, I stated that I didn’t have time for that and covered only the part of the challenge not related to SVG. I also said that, in the event that I find some time over the weekend, I might come back and fulfill the SVG part. I thought at the time that this was rather unlikely, but I was finally able to cover the SVG part, at least in Raku.

Task 1: Scalable Vector Graphics (SVG)

Installing wxPerl for Strawberry Perl v5.32.0, or: Future of wxPerl?

I've been wanting to explore the Wx GUI toolkit bindings for Perl, but I couldn't get it to install correctly on my 64-bit Windows 7 machine.

When I ran cpan Wx, it failed to install the dependency Alien::wxWidgets. There were some cryptic errors about CreateProcess, which is (basically) Windows' equivalent of fork(2). Presumably, some process started by the build script was having some problems, but there wasn't much in the error message to go on.

From Google, I found an old reply posted on PerlMonks by Mark Dootson, the maintainer of Wx and Alien::wxWidgets, where he recommended to make sure to correctly set the PATH before building it.

Technically, my PATH seemed fine – it had all the necessary Perl directories in it. Still, suspecting that the problems may be caused by some other directory in the PATH, I reduced it to its bare elements and then ran cpan again:

EV charge pricing per State in US

Continuing from my previous post ( https://blogs.perl.org/users/itcharlie/2021/04/calculating-ev-battery-charge-with-perl.html ) I learned that residential electricity charges are calculated using an electricity supply rate per kWh and a electric delivery rate per kWh which actually increases the total EV charge prices that I have calculated in my previous post. My current bill states that my electric supply rate is at 6.9057 cents per kWh and my delivery rate is 11.1785 cents per kWh making it a total of 18.0842 cents per kWh which is 5 cents more than my original post at $ 0.13 cents per kWh.

CY's Take on PWC#109

If you want to challenge yourself on programming, especially on Perl and/or Raku, go to https://perlweeklychallenge.org, code the latest challenges, submit codes on-time (by GitHub or email).

ch2_wk109.png

Task 1: Chowla Numbers

#!/usr/bin/perl
# The Weekly Challenge - 109 
Task 1 Chowla Numbers
use strict;
use warnings;
my $F = $ARGV[0] || 20;
my @chowla_seq = (0,0,0);
for my $n (4..$F) {
    my $s = 0;
    for my $k (2..$n-1) {
        $s += $k unless $n % $k;
    }
    push @chowla_seq$s;
}
print join ""@chowla_seq;
print "\n";
Employ no special tricks here except the use of unless and (roughly speaking?)the boolean value of 0 is equivalent to undef, while both mean false.

Task 2: Four Squares Puzzle

There are many improvisations we can do with it. The task is "N Boxes Puzzle" on my mind.
JavaFX

Perl Weekly Challenge 165: Line of Best Fit

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

Spoiler Alert: This weekly challenge deadline is due in a few of days from now (on May 22, 2022 at 24:00). This blog post offers some (partial) solutions to this challenge, please don’t read on if you intend to complete the challenge on your own.

Perl performance on Apple M1

I recently got an Apple M1 Mac Mini, half out of curiosity, half because it was exactly what I would need: I have a low end Mac just to try out things like new Xcode betas etc, like a "canary" machine. My old 2012 Mac Mini stopped getting official Apple updates, so it could no longer do what I needed and the 8GB RAM, 256GB SSD M1 mini at $699 is easily the cheapest Mac you can buy.
Overall, unlike the typical Mac Minis of old which seemed to be on the slow side, it did feel quite fast from the start, so I thought I'd run some benchmarks on it for fun to see how Apple's ARM M1 fares against some x86 competition. And, as in my day job I use mostly Perl, I thought some perl-related benchmarks would be of interest to me.

Dancer2 0.301002 Released

On behalf of the Dancer Core Team, I'd like to announce the availability of Dancer2 0.301002. This release includes a number of enhancements and documentation changes along with several bugfixes. The most notable enhancement is a brand new command line interface, and I highly encourage you to check it out.

Proposal for Perl Foundation Memberships

The current Yet Another Society (The Perl Foundation) bylaws exclude the possibility of membership (see Article II https://www.perlfoundation.org/bylaws.html). As reference, the Python Foundation has 5 membership classes with various rights and privileges associated (https://www.python.org/psf/bylaws/).

I believe this to be a wasted opportunity to increase engagement with stake holders in the Perl community, be they individuals, business or other organizations. And also to secure funding for vital Perl related activities arranged by the Perl Foundation.

Rather than a complicated class system,a good starting point would be a single membership option with an annual renewal and no specific benefits than a warm feeling. (Although, throwing in some exclusive swag and a membership card might not be a bad little bonus)

This could then evolve based on feedback via a membership committee.

I have sent a brief proposal to the YAS (TPF) board to this effect. I invite your support in comments below and/or by contacting board members voicing your support (see https://www.perlfoundation.org/committees.html)

Perl Weekly Challenge 164: Prime Palindromes and Happy Numbers

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

Spoiler Alert: This weekly challenge deadline is due in a few of days from now (on May 15, 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: Prime Palindromes

Write a script to find all prime numbers less than 1000, which are also palindromes in base 10. Palindromic numbers are numbers whose digits are the same in reverse. For example, 313 is a palindromic prime, but 337 is not, even though 733 (337 reversed) is also prime.

Prime Palindromes in Raku

We use a data pipeline (chained method invocations) with two grep statements, one to keep palindromes and one to keep prime numbers. This leads to a fairly concise one-line solution:

say (1..^1000).grep({ $_ == .flip }).grep({.is-prime});

Calculating EV battery charge pricing with Perl

Presently I have great interest in “EVs” Electric Vehicles but I haven’t seen any data on how much it would cost to charge an electric vehicle from 0 % to 100 % battery charge at home in NYC ( So I wrote a Perl script to do just that ) but before we dig in into it I explain a few things about Electric Vehicles.

Electric Vehicles will have a battery capacity that is represented by kilowatt-hour units or kWh for short.

An EV’s driving range is represented in miles units ( In the US ) and the average mileage is determined by the EPA battery range rating ( the bigger the battery capacity usually means the more driving range you will have in a car ) after conducting a few tests ( so in reality your mileage will vary ).

Monthly Report - March

Celebration time ...

The month of March is very special to me. It was in this month 2 years ago, I started my dream project The Weekly Challenge (a.k.a. Perl Weekly Challenge).

Kent Fredric's CPAN distributions are available for adoption

As most of you are probably aware, Kent Fredric sadly passed away earlier this year: notice from his family, on Facebook.

Kent was a prolific contributor to CPAN and Perl. He released more than 150 distributions of his own to CPAN, but also helped countless other authors and distributions, with bug reports, puil requests, and more.

When a CPAN author dies, their indexing permissions are dropped from PAUSE, and where they had the first-come permission, that will be passed to the pseudo-user ADOPTME. This flags the distribution as being available for adoption.

So as of now, all of Kent's distributions are available for adoption.

Perl Weekly Challenge 163: Sum Bitwise Operator and Summations

These are some answers to the Week 163 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 May 8, 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: Sum Bitwise Operator

You are given list positive numbers, @n.

Write script to calculate the sum of bitwise & operator for all unique pairs.

Example 1:

Input: @n = (1, 2, 3)
Output: 3

Since (1 & 2) + (2 & 3) + (1 & 3) => 0 + 2 + 1 =>  3.

Example 2:

Switch lots of things on at once

Many people already have codes like

use strict;
use warnings;

and so on at the top of each script they write. For scripts which I don't intend to publish anywhere, I have a module (which I accidentally called Z not knowing there was already a module of the same name on CPAN), which switches on lots of things at once just by saying

use Z;

The top bit goes like this:

[Personal Review] Codes from The Weekly Challenge Week 095-105

If you want to challenge yourself on programming, especially on Perl and/or Raku, go to https://perlweeklychallenge.org, code the latest challenges, submit codes on-time (by GitHub or email).

-------------------------------------

My coding momentum is a bit low.

Reflections on the codes I have written:

#095

Task 1: Palindrome Number
TMTOWTDI. On this seemly and actually simple task, I chose to compare the digit one by one.

Task 2: Demo Stack
A bit smell of laziness. I did not provide functions when stack is empty and pop() or min() is called.

#096

Task 1: Reverse Words
A lesson on extra-white space. Oppositely but as lack of caution as a sin, this morning (GMT+8) I found I have forgotten a newline for my code for #105 Task 1.

Task 2: Edit Distance
That was a standard computer science exercise. I was astounded by reading Mr Abigail's blog on the approach on saving memory space.

#097

Task 1: Caesar Cipher
Trivial.

In defence of OOP

During the last years it became fashionable to rag on object oriented programming and a decade ago I would join the choir. Hack, when I started with Perl I despised the bloat and inefficiency of many corporate smelling *coughjava* systems and preached the light weight and foreward thinking way that real hackers travel. In this miniseries I want to write why I changed my tune [part one], the best way (IMO) to use OOP [part two] and why inheritance (incl. roles and templates) and delegation or not helpful features (in contrast to polymorphism) [part three]. Maybe there will be more about rating Perl OO features and modules.

Perl Weekly Challenge 162: ISBN-13 and Wheatstone-Playfair

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

Spoiler Alert: This weekly challenge deadline is due in a couple of days from now (on May 1st, 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: ISBN-13

Write a script to generate the check digit of given ISBN-13 code. Please refer wikipedia for more information.

Example

ISBN-13 check digit for '978-0-306-40615-7' is 7.

This how Wikipedia describes the calculation of the ISBN-13 check digit:

Reimagining perl5-porters email list for 2021 and beyond

Let's examine if in 2021 an email redistribution list, i.e. perl5-porters@ (p5p) is still the best model for collaborating on the perl language. This is a discussion so comment below!

Advantages of an email list:

  • Familiar interface, people can use their client of choice
  • Low resources to run and maintain
  • Easy to derive automation from as email is all well known protocols
  • Everything is email

Disadvantages of an email list:

  • Email addresses disclosed to all participants (can be changed)
  • UI experience for participants inconsistent, may require client side configuration to "get right"
  • Email "reply" text can lower the signal to noise ratio
  • No topic categorization of posts, its all dumped in to your inbox
  • Tricky to respond to missed emails
  • Moderation is crude, every email is reviewed and approved, or everything is approved
  • Once an email is relayed it can't be moderated further
  • Encourages side channel correspondence
  • Everything is email

Given the long list of disadvantages we can guess why email lists (and newsgroups) have largely fallen by the wayside.

Perl weekly challenge 105

Here are solutions to this weeks challenges from the Perl Weekly Challenge.

You can find my full code on Github

Nth root

You are given positive numbers $N and $k.

Write a script to find out the $Nth root of $k.

The solution

I decided that I would not go the easy way this week and just use the power function ** i.e. return $k**(1/$N).

Instead for integer values of $N, solve this with only using the simple mathematical operators +, /, *, -, <, >

To do this we will use a divide and conquer solution, starting at the two ends of the interval we calculate the values of x^N, and then iterate reducing the interval in half - choosing the interval where the value of x^N is less than k at the left hand end & x^N is greater than k.

To do this we store the value of the ends of the interval as l and r respectively and computer the Nth power of each (ln & rn).

Subject Verb Object notation; declarative Perl without the framework

If you’ve read Curtis “Ovid” Poe’s articles on the declarative framework for Tau Station Link and Link, you are undoubtedly aware of many of the benefits this style of programming can bring. It decouples the “what” from the “how”, encourages discrete functions and prevents the OO trap of “god objects”. The result is software that is easy to test, robust and very flexible. Inserting steps, reording steps etc… are done much easier and more clearly than trying to figure this out in 300 lines of imperative code with four to six level deep if-else chains with for loops mixed in for good fun. However, the framework is tightly coupled to the game in spots and has a few other issues that make it not ready for general use.

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.